Add mjmModel opaque pointer to C API.
PiperOrigin-RevId: 607619891 Change-Id: Ic1eaaa842438d9c2e19f742deff41967287853f5
This commit is contained in:
committed by
Copybara-Service
parent
f9f7827a64
commit
5e353efaaf
@@ -2263,7 +2263,7 @@ void mjXReader::OneComposite(XMLElement* elem, mjmBody* pbody, mjmDefault* def)
|
||||
ReadAttrTxt(eplugin, "plugin", comp.plugin_name);
|
||||
ReadAttrTxt(eplugin, "instance", comp.plugin_instance_name);
|
||||
if (comp.plugin_instance_name.empty()) {
|
||||
comp.plugin_instance = (mjCPlugin*)mjm_addPlugin(model);
|
||||
comp.plugin_instance = (mjCPlugin*)mjm_addPlugin(&model->spec);
|
||||
comp.plugin_instance->name = "composite"+comp.prefix;
|
||||
comp.plugin_instance_name = comp.plugin_instance->name;
|
||||
} else {
|
||||
@@ -2594,7 +2594,7 @@ void mjXReader::OneFlexcomp(XMLElement* elem, mjmBody* pbody) {
|
||||
ReadAttrTxt(eplugin, "plugin", fcomp.plugin_name);
|
||||
ReadAttrTxt(eplugin, "instance", fcomp.plugin_instance_name);
|
||||
if (fcomp.plugin_instance_name.empty()) {
|
||||
fcomp.plugin_instance = (mjCPlugin*)mjm_addPlugin(model);
|
||||
fcomp.plugin_instance = (mjCPlugin*)mjm_addPlugin(&model->spec);
|
||||
fcomp.plugin_instance->name = "flexcomp_" + fcomp.name;
|
||||
fcomp.plugin_instance_name = fcomp.plugin_instance->name;
|
||||
} else {
|
||||
@@ -2625,7 +2625,7 @@ void mjXReader::OnePlugin(XMLElement* elem, mjmPlugin* plugin) {
|
||||
mjm_setString(plugin->name, name.c_str());
|
||||
mjm_setString(plugin->instance_name, instance_name.c_str());
|
||||
if (instance_name.empty()) {
|
||||
plugin->instance = mjm_addPlugin(model);
|
||||
plugin->instance = mjm_addPlugin(&model->spec);
|
||||
ReadPluginConfigs(elem, (mjCPlugin*)plugin->instance);
|
||||
} else {
|
||||
model->hasImplicitPluginElem = true;
|
||||
@@ -2655,7 +2655,7 @@ void mjXReader::Default(XMLElement* section, int parentid) {
|
||||
}
|
||||
if (parentid>=0) {
|
||||
thisid = (int)model->defaults.size();
|
||||
def = mjm_addDefault(model, text.c_str(), parentid);
|
||||
def = mjm_addDefault(&model->spec, text.c_str(), parentid);
|
||||
if (!def) {
|
||||
throw mjXError(section, "repeated default class name");
|
||||
}
|
||||
@@ -2784,7 +2784,7 @@ void mjXReader::Extension(XMLElement* section) {
|
||||
throw mjXError(
|
||||
child, "explicit plugin instance must appear before implicit plugin elements");
|
||||
}
|
||||
mjCPlugin* pp = (mjCPlugin*)mjm_addPlugin(model);
|
||||
mjCPlugin* pp = (mjCPlugin*)mjm_addPlugin(&model->spec);
|
||||
GetXMLPos(child, pp);
|
||||
ReadAttrTxt(child, "name", pp->name, /* required = */ true);
|
||||
if (pp->name.empty()) {
|
||||
@@ -2821,7 +2821,7 @@ void mjXReader::Custom(XMLElement* section) {
|
||||
// numeric
|
||||
if (name=="numeric") {
|
||||
// create custom
|
||||
mjmNumeric* pnum = mjm_addNumeric(model);
|
||||
mjmNumeric* pnum = mjm_addNumeric(&model->spec);
|
||||
|
||||
// write error info
|
||||
mjm_setString(pnum->info,
|
||||
@@ -2853,7 +2853,7 @@ void mjXReader::Custom(XMLElement* section) {
|
||||
// text
|
||||
else if (name=="text") {
|
||||
// create custom
|
||||
mjmText* pte = mjm_addText(model);
|
||||
mjmText* pte = mjm_addText(&model->spec);
|
||||
|
||||
// write error info
|
||||
mjm_setString(pte->info,
|
||||
@@ -2874,7 +2874,7 @@ void mjXReader::Custom(XMLElement* section) {
|
||||
// tuple
|
||||
else if (name=="tuple") {
|
||||
// create custom
|
||||
mjmTuple* ptu = mjm_addTuple(model);
|
||||
mjmTuple* ptu = mjm_addTuple(&model->spec);
|
||||
|
||||
// write error info
|
||||
mjm_setString(ptu->info,
|
||||
@@ -3082,7 +3082,7 @@ void mjXReader::Asset(XMLElement* section) {
|
||||
// texture sub-element
|
||||
if (name=="texture") {
|
||||
// create texture
|
||||
mjmTexture* ptex = mjm_addTexture(model);
|
||||
mjmTexture* ptex = mjm_addTexture(&model->spec);
|
||||
|
||||
// write error info
|
||||
mjm_setString(ptex->info,
|
||||
@@ -3150,28 +3150,28 @@ void mjXReader::Asset(XMLElement* section) {
|
||||
// material sub-element
|
||||
else if (name=="material") {
|
||||
// create material and parse
|
||||
mjmMaterial* pmat = mjm_addMaterial(model, def);
|
||||
mjmMaterial* pmat = mjm_addMaterial(&model->spec, def);
|
||||
OneMaterial(elem, pmat);
|
||||
}
|
||||
|
||||
// mesh sub-element
|
||||
else if (name=="mesh") {
|
||||
// create mesh and parse
|
||||
mjmMesh* pmesh = mjm_addMesh(model, def);
|
||||
mjmMesh* pmesh = mjm_addMesh(&model->spec, def);
|
||||
OneMesh(elem, pmesh);
|
||||
}
|
||||
|
||||
// skin sub-element... deprecate ???
|
||||
else if (name=="skin") {
|
||||
// create skin and parse
|
||||
mjmSkin* pskin = mjm_addSkin(model);
|
||||
mjmSkin* pskin = mjm_addSkin(&model->spec);
|
||||
OneSkin(elem, pskin);
|
||||
}
|
||||
|
||||
// hfield sub-element
|
||||
else if (name=="hfield") {
|
||||
// create hfield
|
||||
mjmHField* phf = mjm_addHField(model);
|
||||
mjmHField* phf = mjm_addHField(&model->spec);
|
||||
|
||||
// write error info
|
||||
mjm_setString(phf->info,
|
||||
@@ -3453,13 +3453,13 @@ void mjXReader::Contact(XMLElement* section) {
|
||||
// geom pair to include
|
||||
if (name=="pair") {
|
||||
// create pair and parse
|
||||
mjmPair* ppair = mjm_addPair(model, def);
|
||||
mjmPair* ppair = mjm_addPair(&model->spec, def);
|
||||
OnePair(elem, ppair);
|
||||
}
|
||||
|
||||
// body pair to exclude
|
||||
else if (name=="exclude") {
|
||||
mjmExclude* pexclude = mjm_addExclude(model);
|
||||
mjmExclude* pexclude = mjm_addExclude(&model->spec);
|
||||
string exname, exbody1, exbody2;
|
||||
|
||||
// write error info
|
||||
@@ -3496,7 +3496,7 @@ void mjXReader::Equality(XMLElement* section) {
|
||||
}
|
||||
|
||||
// create equality constraint and parse
|
||||
mjmEquality* pequality = mjm_addEquality(model, def);
|
||||
mjmEquality* pequality = mjm_addEquality(&model->spec, def);
|
||||
OneEquality(elem, pequality);
|
||||
|
||||
// advance to next element
|
||||
@@ -3526,14 +3526,14 @@ void mjXReader::Deformable(XMLElement* section) {
|
||||
// flex sub-element
|
||||
if (name=="flex") {
|
||||
// create flex and parse
|
||||
mjmFlex* pflex = mjm_addFlex(model);
|
||||
mjmFlex* pflex = mjm_addFlex(&model->spec);
|
||||
OneFlex(elem, pflex);
|
||||
}
|
||||
|
||||
// skin sub-element
|
||||
else if (name=="skin") {
|
||||
// create skin and parse
|
||||
mjmSkin* pskin = mjm_addSkin(model);
|
||||
mjmSkin* pskin = mjm_addSkin(&model->spec);
|
||||
OneSkin(elem, pskin);
|
||||
}
|
||||
|
||||
@@ -3560,7 +3560,7 @@ void mjXReader::Tendon(XMLElement* section) {
|
||||
}
|
||||
|
||||
// create equality constraint and parse
|
||||
mjmTendon* pten = mjm_addTendon(model, def);
|
||||
mjmTendon* pten = mjm_addTendon(&model->spec, def);
|
||||
OneTendon(elem, pten);
|
||||
|
||||
// process wrap sub-elements
|
||||
@@ -3626,7 +3626,7 @@ void mjXReader::Actuator(XMLElement* section) {
|
||||
}
|
||||
|
||||
// create actuator and parse
|
||||
mjmActuator* pact = mjm_addActuator(model, def);
|
||||
mjmActuator* pact = mjm_addActuator(&model->spec, def);
|
||||
OneActuator(elem, pact);
|
||||
|
||||
// advance to next element
|
||||
@@ -3642,7 +3642,7 @@ void mjXReader::Sensor(XMLElement* section) {
|
||||
XMLElement* elem = FirstChildElement(section);
|
||||
while (elem) {
|
||||
// create sensor, get string type
|
||||
mjmSensor* psen = mjm_addSensor(model);
|
||||
mjmSensor* psen = mjm_addSensor(&model->spec);
|
||||
string type = elem->Value();
|
||||
string text, name, objname, refname;
|
||||
std::vector<double> userdata;
|
||||
@@ -3960,7 +3960,7 @@ void mjXReader::Keyframe(XMLElement* section) {
|
||||
string text, name = "";
|
||||
|
||||
// add keyframe
|
||||
mjmKey* pk = mjm_addKey(model);
|
||||
mjmKey* pk = mjm_addKey(&model->spec);
|
||||
|
||||
// read name, time
|
||||
ReadAttrTxt(elem, "name", name);
|
||||
|
||||
+7
-7
@@ -202,7 +202,7 @@ void mjXURDF::Parse(
|
||||
// override the pose for the base link and add a free joint
|
||||
for (int i = 0; i < (int)urName.size(); i++) {
|
||||
if (urParent[i] < 0) {
|
||||
mjmBody* world = mjm_findBody(model, "world");
|
||||
mjmBody* world = mjm_findBody(&model->spec, "world");
|
||||
mjmBody* pbody = mjm_findChild(world, urName[i].c_str());
|
||||
mjuu_copyvec(pbody->pos, pos, 3);
|
||||
mjuu_copyvec(pbody->quat, quat, 4);
|
||||
@@ -228,7 +228,7 @@ void mjXURDF::Body(XMLElement* body_elem) {
|
||||
// get body name and pointer to mjmBody
|
||||
ReadAttrTxt(body_elem, "name", name, true);
|
||||
name = GetPrefixedName(name);
|
||||
world = mjm_findBody(model, "world");
|
||||
world = mjm_findBody(&model->spec, "world");
|
||||
pbody = mjm_findChild(world, name.c_str());
|
||||
if (!pbody) {
|
||||
throw mjXError(body_elem, "URDF body not found"); // SHOULD NOT OCCUR
|
||||
@@ -386,7 +386,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) {
|
||||
elem = FindSubElem(joint_elem, "parent", true);
|
||||
ReadAttrTxt(elem, "link", name, true);
|
||||
name = GetPrefixedName(name);
|
||||
world = mjm_findBody(model, "world");
|
||||
world = mjm_findBody(&model->spec, "world");
|
||||
parent = mjm_findChild(world, name.c_str());
|
||||
if (!parent) { // SHOULD NOT OCCUR
|
||||
throw mjXError(elem, "invalid parent name in URDF joint definition");
|
||||
@@ -396,7 +396,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) {
|
||||
elem = FindSubElem(joint_elem, "child", true);
|
||||
ReadAttrTxt(elem, "link", name, true);
|
||||
name = GetPrefixedName(name);
|
||||
world = mjm_findBody(model, "world");
|
||||
world = mjm_findBody(&model->spec, "world");
|
||||
pbody = mjm_findChild(world, name.c_str());
|
||||
if (!pbody) { // SHOULD NOT OCCUR
|
||||
throw mjXError(elem, "invalid child name in URDF joint definition");
|
||||
@@ -577,14 +577,14 @@ mjmGeom* mjXURDF::Geom(XMLElement* geom_elem, mjmBody* pbody, bool collision) {
|
||||
|
||||
// does not exist: create
|
||||
if (!mesh) {
|
||||
pmesh = mjm_addMesh(model, 0);
|
||||
pmesh = mjm_addMesh(&model->spec, 0);
|
||||
}
|
||||
|
||||
// exists with different scale: append name with '1', create
|
||||
else if (mesh->spec.scale[0]!=meshscale[0] ||
|
||||
mesh->spec.scale[1]!=meshscale[1] ||
|
||||
mesh->spec.scale[2]!=meshscale[2]) {
|
||||
pmesh = mjm_addMesh(model, 0);
|
||||
pmesh = mjm_addMesh(&model->spec, 0);
|
||||
meshname = meshname + "1";
|
||||
}
|
||||
|
||||
@@ -681,7 +681,7 @@ void mjXURDF::AddToTree(int n) {
|
||||
// get pointer to parent in mjCModel tree
|
||||
mjmBody *parent = 0, *child = 0, *world = 0;
|
||||
if (urParent[n]>=0) {
|
||||
world = mjm_findBody(model, "world");
|
||||
world = mjm_findBody(&model->spec, "world");
|
||||
parent = mjm_findChild(world, urName[urParent[n]].c_str());
|
||||
|
||||
if (!parent)
|
||||
|
||||
Reference in New Issue
Block a user