Use OnePlugin for parsing Composite and Flexcomp plugins.
PiperOrigin-RevId: 608265172 Change-Id: I053441a9e534d81c4847ad60fe4a3f7dce87350c
This commit is contained in:
committed by
Copybara-Service
parent
55e2c76c01
commit
b77dfc683a
@@ -315,10 +315,11 @@ mjmKey* mjm_addKey(mjmModel* model) {
|
|||||||
|
|
||||||
|
|
||||||
// add plugin to model
|
// add plugin to model
|
||||||
mjElement mjm_addPlugin(mjmModel* model) {
|
mjmPlugin* mjm_addPlugin(mjmModel* model) {
|
||||||
mjCModel* modelC = reinterpret_cast<mjCModel*>(model->element);
|
mjCModel* modelC = reinterpret_cast<mjCModel*>(model->element);
|
||||||
mjCPlugin* plugin = modelC->AddPlugin();
|
mjCPlugin* plugin = modelC->AddPlugin();
|
||||||
return (mjElement)plugin;
|
plugin->plugin.instance = (mjElement)plugin;
|
||||||
|
return &plugin->plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -761,7 +761,7 @@ MJAPI mjmTuple* mjm_addTuple(mjmModel* model);
|
|||||||
MJAPI mjmKey* mjm_addKey(mjmModel* model);
|
MJAPI mjmKey* mjm_addKey(mjmModel* model);
|
||||||
|
|
||||||
// Add plugin to model.
|
// Add plugin to model.
|
||||||
MJAPI mjElement mjm_addPlugin(mjmModel* model);
|
MJAPI mjmPlugin* mjm_addPlugin(mjmModel* model);
|
||||||
|
|
||||||
// Add default to 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);
|
||||||
@@ -895,6 +895,9 @@ MJAPI void mjm_defaultTuple(mjmTuple& tuple);
|
|||||||
// Default keyframe attributes.
|
// Default keyframe attributes.
|
||||||
MJAPI void mjm_defaultKey(mjmKey& key);
|
MJAPI void mjm_defaultKey(mjmKey& key);
|
||||||
|
|
||||||
|
// Default plugin attributes.
|
||||||
|
MJAPI void mjm_defaultPlugin(mjmPlugin& plugin);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+26
-18
@@ -64,7 +64,13 @@ mjCComposite::mjCComposite(void) {
|
|||||||
pin.clear();
|
pin.clear();
|
||||||
flatinertia = 0;
|
flatinertia = 0;
|
||||||
mj_defaultSolRefImp(solrefsmooth, solimpsmooth);
|
mj_defaultSolRefImp(solrefsmooth, solimpsmooth);
|
||||||
plugin_instance = nullptr;
|
|
||||||
|
// plugin variables
|
||||||
|
mjm_defaultPlugin(plugin);
|
||||||
|
plugin_name = "";
|
||||||
|
plugin_instance_name = "";
|
||||||
|
plugin.name = (mjString)&plugin_name;
|
||||||
|
plugin.instance_name = (mjString)&plugin_instance_name;
|
||||||
|
|
||||||
// cable
|
// cable
|
||||||
curve[0] = curve[1] = curve[2] = mjCOMPSHAPE_ZERO;
|
curve[0] = curve[1] = curve[2] = mjCOMPSHAPE_ZERO;
|
||||||
@@ -423,9 +429,10 @@ bool mjCComposite::MakeParticle(mjCModel* model, mjmBody* body, char* error, int
|
|||||||
// compute volume
|
// compute volume
|
||||||
std::vector<mjtNum> volume(uservert.size()/3);
|
std::vector<mjtNum> volume(uservert.size()/3);
|
||||||
mjtNum t = 1;
|
mjtNum t = 1;
|
||||||
if (dim == 2 && plugin_instance) {
|
if (dim == 2 && plugin.active) {
|
||||||
try {
|
try {
|
||||||
t = std::stod(plugin_instance->config_attribs["thickness"], nullptr);
|
mjCPlugin* pplugin = (mjCPlugin*)plugin.instance;
|
||||||
|
t = std::stod(pplugin->config_attribs["thickness"], nullptr);
|
||||||
} catch (const std::invalid_argument& e) {
|
} catch (const std::invalid_argument& e) {
|
||||||
return comperr(error, "Invalid thickness attribute", error_sz);
|
return comperr(error, "Invalid thickness attribute", error_sz);
|
||||||
}
|
}
|
||||||
@@ -502,19 +509,20 @@ bool mjCComposite::MakeParticle(mjCModel* model, mjmBody* body, char* error, int
|
|||||||
mjm_setString(s->name, txt);
|
mjm_setString(s->name, txt);
|
||||||
|
|
||||||
// add plugin
|
// add plugin
|
||||||
if (plugin_instance) {
|
if (plugin.active) {
|
||||||
mjmPlugin* plugin = &b->plugin;
|
mjmPlugin* pplugin = &b->plugin;
|
||||||
plugin->active = true;
|
mjCPlugin* cplugin = (mjCPlugin*)plugin.instance;
|
||||||
plugin->instance = (mjElement)plugin_instance;
|
pplugin->active = true;
|
||||||
mjm_setString(plugin->instance_name, plugin_instance_name.c_str());
|
pplugin->instance = (mjElement)plugin.instance;
|
||||||
mjm_setString(plugin->name, plugin_name.c_str());
|
mjm_setString(pplugin->instance_name, plugin_instance_name.c_str());
|
||||||
|
mjm_setString(pplugin->name, mjm_getString(plugin.name));
|
||||||
|
|
||||||
if (i==0 && !plugin_instance->config_attribs["face"].empty()) {
|
if (i==0 && !cplugin->config_attribs["face"].empty()) {
|
||||||
return comperr(error, "Face attribute already exists in plugin", error_sz);
|
return comperr(error, "Face attribute already exists in plugin", error_sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin_instance->config_attribs["face"] = userface;
|
cplugin->config_attribs["face"] = userface;
|
||||||
plugin_instance->config_attribs["edge"] = "";
|
cplugin->config_attribs["edge"] = "";
|
||||||
|
|
||||||
// update density
|
// update density
|
||||||
if (dim == 2) {
|
if (dim == 2) {
|
||||||
@@ -856,12 +864,12 @@ mjmBody* mjCComposite::AddCableBody(mjCModel* model, mjmBody* body, int ix, mjtN
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add plugin
|
// add plugin
|
||||||
if (plugin_instance) {
|
if (plugin.active) {
|
||||||
mjmPlugin* plugin = &body->plugin;
|
mjmPlugin* pplugin = &body->plugin;
|
||||||
plugin->active = true;
|
pplugin->active = true;
|
||||||
plugin->instance = (mjElement)plugin_instance;
|
pplugin->instance = (mjElement)plugin.instance;
|
||||||
mjm_setString(plugin->name, plugin_name.c_str());
|
mjm_setString(pplugin->name, mjm_getString(plugin.name));
|
||||||
mjm_setString(plugin->instance_name, plugin_instance_name.c_str());
|
mjm_setString(pplugin->instance_name, plugin_instance_name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// update orientation
|
// update orientation
|
||||||
|
|||||||
@@ -114,10 +114,9 @@ class mjCComposite {
|
|||||||
std::vector<std::string> username;
|
std::vector<std::string> username;
|
||||||
|
|
||||||
// plugin support
|
// plugin support
|
||||||
bool is_plugin;
|
|
||||||
std::string plugin_name;
|
std::string plugin_name;
|
||||||
std::string plugin_instance_name;
|
std::string plugin_instance_name;
|
||||||
mjCPlugin* plugin_instance;
|
mjmPlugin plugin;
|
||||||
|
|
||||||
// skin
|
// skin
|
||||||
bool skin; // generate skin
|
bool skin; // generate skin
|
||||||
|
|||||||
+18
-13
@@ -71,7 +71,12 @@ mjCFlexcomp::mjCFlexcomp(void) {
|
|||||||
mjuu_setvec(quat, 1, 0, 0, 0);
|
mjuu_setvec(quat, 1, 0, 0, 0);
|
||||||
rigid = false;
|
rigid = false;
|
||||||
centered = false;
|
centered = false;
|
||||||
plugin_instance = nullptr;
|
|
||||||
|
mjm_defaultPlugin(plugin);
|
||||||
|
plugin_name = "";
|
||||||
|
plugin_instance_name = "";
|
||||||
|
plugin.name = (mjString)&plugin_name;
|
||||||
|
plugin.instance_name = (mjString)&plugin_instance_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -404,12 +409,12 @@ bool mjCFlexcomp::Make(mjCModel* model, mjmBody* body, char* error, int error_sz
|
|||||||
mjm_appendString(pf->vertbody, mjm_getString(body->name));
|
mjm_appendString(pf->vertbody, mjm_getString(body->name));
|
||||||
|
|
||||||
// add plugin
|
// add plugin
|
||||||
if (plugin_instance) {
|
if (plugin.active) {
|
||||||
mjmPlugin* plugin = &body->plugin;
|
mjmPlugin* pplugin = &body->plugin;
|
||||||
plugin->active = true;
|
pplugin->active = true;
|
||||||
plugin->instance = (mjElement)plugin_instance;
|
pplugin->instance = (mjElement)plugin.instance;
|
||||||
mjm_setString(plugin->name, plugin_name.c_str());
|
mjm_setString(pplugin->name, mjm_getString(plugin.name));
|
||||||
mjm_setString(plugin->instance_name, plugin_instance_name.c_str());
|
mjm_setString(pplugin->instance_name, plugin_instance_name.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -468,12 +473,12 @@ bool mjCFlexcomp::Make(mjCModel* model, mjmBody* body, char* error, int error_sz
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add plugin
|
// add plugin
|
||||||
if (plugin_instance) {
|
if (plugin.active) {
|
||||||
mjmPlugin* plugin = &pb->plugin;
|
mjmPlugin* pplugin = &pb->plugin;
|
||||||
plugin->active = true;
|
pplugin->active = true;
|
||||||
plugin->instance = (mjElement)plugin_instance;
|
pplugin->instance = (mjElement)plugin.instance;
|
||||||
mjm_setString(plugin->name, plugin_name.c_str());
|
mjm_setString(pplugin->name, mjm_getString(plugin.name));
|
||||||
mjm_setString(plugin->instance_name, plugin_instance_name.c_str());
|
mjm_setString(pplugin->instance_name, plugin_instance_name.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <mujoco/mujoco.h>
|
#include <mujoco/mujoco.h>
|
||||||
|
#include "user/user_api.h"
|
||||||
#include "user/user_model.h"
|
#include "user/user_model.h"
|
||||||
#include "user/user_objects.h"
|
#include "user/user_objects.h"
|
||||||
|
|
||||||
@@ -87,10 +88,9 @@ class mjCFlexcomp {
|
|||||||
std::vector<float> texcoord; // vertex texture coordinates
|
std::vector<float> texcoord; // vertex texture coordinates
|
||||||
|
|
||||||
// plugin support
|
// plugin support
|
||||||
bool is_plugin;
|
|
||||||
std::string plugin_name;
|
std::string plugin_name;
|
||||||
std::string plugin_instance_name;
|
std::string plugin_instance_name;
|
||||||
mjCPlugin* plugin_instance;
|
mjmPlugin plugin;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MUJOCO_SRC_USER_USER_FLEXCOMP_H_
|
#endif // MUJOCO_SRC_USER_USER_FLEXCOMP_H_
|
||||||
|
|||||||
@@ -366,3 +366,9 @@ void mjm_defaultKey(mjmKey& key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// default plugin attributes
|
||||||
|
void mjm_defaultPlugin(mjmPlugin& plugin) {
|
||||||
|
memset(&plugin, 0, sizeof(mjmPlugin));
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -546,8 +546,7 @@ mjCBase::mjCBase() {
|
|||||||
frame = nullptr;
|
frame = nullptr;
|
||||||
|
|
||||||
// plugin variables
|
// plugin variables
|
||||||
plugin.active = false;
|
mjm_defaultPlugin(plugin);
|
||||||
plugin.instance = nullptr;
|
|
||||||
plugin_name = "";
|
plugin_name = "";
|
||||||
plugin_instance_name = "";
|
plugin_instance_name = "";
|
||||||
plugin.name = (mjString)&plugin_name;
|
plugin.name = (mjString)&plugin_name;
|
||||||
@@ -5337,6 +5336,13 @@ mjCPlugin::mjCPlugin(mjCModel* _model) {
|
|||||||
nstate = 0;
|
nstate = 0;
|
||||||
parent = this;
|
parent = this;
|
||||||
model = _model;
|
model = _model;
|
||||||
|
|
||||||
|
// public interface
|
||||||
|
mjm_defaultPlugin(plugin);
|
||||||
|
plugin_name = "";
|
||||||
|
plugin_instance_name = "";
|
||||||
|
plugin.name = (mjString)&plugin_name;
|
||||||
|
plugin.instance_name = (mjString)&plugin_instance_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2273,16 +2273,11 @@ void mjXReader::OneComposite(XMLElement* elem, mjmBody* pbody, mjmDefault* def)
|
|||||||
// plugin
|
// plugin
|
||||||
XMLElement* eplugin = FirstChildElement(elem, "plugin");
|
XMLElement* eplugin = FirstChildElement(elem, "plugin");
|
||||||
if (eplugin) {
|
if (eplugin) {
|
||||||
ReadAttrTxt(eplugin, "plugin", comp.plugin_name);
|
OnePlugin(eplugin, &comp.plugin);
|
||||||
ReadAttrTxt(eplugin, "instance", comp.plugin_instance_name);
|
|
||||||
if (comp.plugin_instance_name.empty()) {
|
if (comp.plugin_instance_name.empty()) {
|
||||||
comp.plugin_instance = (mjCPlugin*)mjm_addPlugin(&model->spec);
|
comp.plugin_instance_name = "composite" + comp.prefix;
|
||||||
comp.plugin_instance->name = "composite"+comp.prefix;
|
((mjCPlugin*)comp.plugin.instance)->name = comp.plugin_instance_name;
|
||||||
comp.plugin_instance_name = comp.plugin_instance->name;
|
|
||||||
} else {
|
|
||||||
model->hasImplicitPluginElem = true;
|
|
||||||
}
|
}
|
||||||
ReadPluginConfigs(eplugin, comp.plugin_instance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cable
|
// cable
|
||||||
@@ -2604,16 +2599,11 @@ void mjXReader::OneFlexcomp(XMLElement* elem, mjmBody* pbody) {
|
|||||||
// plugin
|
// plugin
|
||||||
XMLElement* eplugin = FirstChildElement(elem, "plugin");
|
XMLElement* eplugin = FirstChildElement(elem, "plugin");
|
||||||
if (eplugin) {
|
if (eplugin) {
|
||||||
ReadAttrTxt(eplugin, "plugin", fcomp.plugin_name);
|
OnePlugin(eplugin, &fcomp.plugin);
|
||||||
ReadAttrTxt(eplugin, "instance", fcomp.plugin_instance_name);
|
|
||||||
if (fcomp.plugin_instance_name.empty()) {
|
if (fcomp.plugin_instance_name.empty()) {
|
||||||
fcomp.plugin_instance = (mjCPlugin*)mjm_addPlugin(&model->spec);
|
fcomp.plugin_instance_name = "flexcomp_" + fcomp.name;
|
||||||
fcomp.plugin_instance->name = "flexcomp_" + fcomp.name;
|
((mjCPlugin*)fcomp.plugin.instance)->name = fcomp.plugin_instance_name;
|
||||||
fcomp.plugin_instance_name = fcomp.plugin_instance->name;
|
|
||||||
} else {
|
|
||||||
model->hasImplicitPluginElem = true;
|
|
||||||
}
|
}
|
||||||
ReadPluginConfigs(eplugin, fcomp.plugin_instance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// make flexcomp
|
// make flexcomp
|
||||||
@@ -2638,7 +2628,7 @@ void mjXReader::OnePlugin(XMLElement* elem, mjmPlugin* plugin) {
|
|||||||
mjm_setString(plugin->name, name.c_str());
|
mjm_setString(plugin->name, name.c_str());
|
||||||
mjm_setString(plugin->instance_name, instance_name.c_str());
|
mjm_setString(plugin->instance_name, instance_name.c_str());
|
||||||
if (instance_name.empty()) {
|
if (instance_name.empty()) {
|
||||||
plugin->instance = mjm_addPlugin(&model->spec);
|
plugin->instance = mjm_addPlugin(&model->spec)->instance;
|
||||||
ReadPluginConfigs(elem, (mjCPlugin*)plugin->instance);
|
ReadPluginConfigs(elem, (mjCPlugin*)plugin->instance);
|
||||||
} else {
|
} else {
|
||||||
model->hasImplicitPluginElem = true;
|
model->hasImplicitPluginElem = true;
|
||||||
@@ -2797,7 +2787,7 @@ void mjXReader::Extension(XMLElement* section) {
|
|||||||
throw mjXError(
|
throw mjXError(
|
||||||
child, "explicit plugin instance must appear before implicit plugin elements");
|
child, "explicit plugin instance must appear before implicit plugin elements");
|
||||||
}
|
}
|
||||||
mjCPlugin* pp = (mjCPlugin*)mjm_addPlugin(&model->spec);
|
mjCPlugin* pp = (mjCPlugin*)mjm_addPlugin(&model->spec)->instance;
|
||||||
GetXMLPos(child, pp);
|
GetXMLPos(child, pp);
|
||||||
ReadAttrTxt(child, "name", pp->name, /* required = */ true);
|
ReadAttrTxt(child, "name", pp->name, /* required = */ true);
|
||||||
if (pp->name.empty()) {
|
if (pp->name.empty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user