Remove mjCPlugin from xml_native_reader.
PiperOrigin-RevId: 608546883 Change-Id: Ib529c2756102e4e2185d1d8e9585187c30049011
This commit is contained in:
committed by
Copybara-Service
parent
b56d4bf8a5
commit
78dc5aee9f
+15
-2
@@ -13,7 +13,10 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "user/user_api.h"
|
#include "user/user_api.h"
|
||||||
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <mujoco/mujoco.h>
|
#include <mujoco/mujoco.h>
|
||||||
@@ -318,8 +321,8 @@ mjmKey* mjm_addKey(mjmModel* model) {
|
|||||||
mjmPlugin* 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();
|
||||||
plugin->plugin.instance = (mjElement)plugin;
|
plugin->spec.instance = (mjElement)plugin;
|
||||||
return &plugin->plugin;
|
return &plugin->spec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -508,6 +511,16 @@ const double* mjm_getDouble(const mjDoubleVec source, int* size) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// set plugin attributes
|
||||||
|
void mjm_setPluginAttributes(mjmPlugin* plugin, void* attributes) {
|
||||||
|
mjCPlugin* pluginC = reinterpret_cast<mjCPlugin*>(plugin->instance);
|
||||||
|
std::map<std::string, std::string, std::less<>>* config_attribs =
|
||||||
|
reinterpret_cast<std::map<std::string, std::string, std::less<>>*>(attributes);
|
||||||
|
pluginC->config_attribs = std::move(*config_attribs);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// compute full inertia
|
// compute full inertia
|
||||||
const char* mjm_setFullInertia(mjmBody* bodyspec, double quat[4], double inertia[3]) {
|
const char* mjm_setFullInertia(mjmBody* bodyspec, double quat[4], double inertia[3]) {
|
||||||
mjCBody* body = reinterpret_cast<mjCBody*>(bodyspec->element);
|
mjCBody* body = reinterpret_cast<mjCBody*>(bodyspec->element);
|
||||||
|
|||||||
+6
-1
@@ -88,7 +88,9 @@ typedef struct _mjmPlugin { // plugin specification
|
|||||||
mjElement instance; // internal, do not modify
|
mjElement instance; // internal, do not modify
|
||||||
mjString name; // name
|
mjString name; // name
|
||||||
mjString instance_name; // instance name
|
mjString instance_name; // instance name
|
||||||
bool active; // is the plugin active
|
int plugin_slot; // global registered slot number of the plugin
|
||||||
|
mjtByte active; // is the plugin active
|
||||||
|
mjString info; // message appended to compiler errors
|
||||||
} mjmPlugin;
|
} mjmPlugin;
|
||||||
|
|
||||||
|
|
||||||
@@ -814,6 +816,9 @@ MJAPI const char* mjm_getString(mjString source);
|
|||||||
// Get double array contents and optionally its size.
|
// Get double array contents and optionally its size.
|
||||||
MJAPI const double* mjm_getDouble(mjDoubleVec source, int* size);
|
MJAPI const double* mjm_getDouble(mjDoubleVec source, int* size);
|
||||||
|
|
||||||
|
// Set plugin attributes.
|
||||||
|
MJAPI void mjm_setPluginAttributes(mjmPlugin* plugin, void* attributes);
|
||||||
|
|
||||||
// Set default.
|
// Set default.
|
||||||
MJAPI void mjm_setDefault(mjElement element, mjmDefault* def);
|
MJAPI void mjm_setDefault(mjElement element, mjmDefault* def);
|
||||||
|
|
||||||
|
|||||||
@@ -308,6 +308,12 @@ bool mjCComposite::Make(mjCModel* model, mjmBody* body, char* error, int error_s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// overwrite plugin name
|
||||||
|
if (plugin_instance_name.empty() && plugin.active) {
|
||||||
|
plugin_instance_name = "composite" + prefix;
|
||||||
|
((mjCPlugin*)plugin.instance)->name = plugin_instance_name;
|
||||||
|
}
|
||||||
|
|
||||||
// dispatch
|
// dispatch
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case mjCOMPTYPE_PARTICLE:
|
case mjCOMPTYPE_PARTICLE:
|
||||||
|
|||||||
@@ -397,6 +397,12 @@ bool mjCFlexcomp::Make(mjCModel* model, mjmBody* body, char* error, int error_sz
|
|||||||
double bodymass = mass/npnt;
|
double bodymass = mass/npnt;
|
||||||
double bodyinertia = bodymass*(2.0*inertiabox*inertiabox)/3.0;
|
double bodyinertia = bodymass*(2.0*inertiabox*inertiabox)/3.0;
|
||||||
|
|
||||||
|
// overwrite plugin name
|
||||||
|
if (plugin.active && plugin_instance_name.empty()) {
|
||||||
|
plugin_instance_name = "flexcomp_" + name;
|
||||||
|
((mjCPlugin*)plugin.instance)->name = plugin_instance_name;
|
||||||
|
}
|
||||||
|
|
||||||
// create bodies, construct flex vert and vertbody
|
// create bodies, construct flex vert and vertbody
|
||||||
for (int i=0; i<npnt; i++) {
|
for (int i=0; i<npnt; i++) {
|
||||||
// not used: skip
|
// not used: skip
|
||||||
|
|||||||
@@ -370,5 +370,6 @@ void mjm_defaultKey(mjmKey& key) {
|
|||||||
// default plugin attributes
|
// default plugin attributes
|
||||||
void mjm_defaultPlugin(mjmPlugin& plugin) {
|
void mjm_defaultPlugin(mjmPlugin& plugin) {
|
||||||
memset(&plugin, 0, sizeof(mjmPlugin));
|
memset(&plugin, 0, sizeof(mjmPlugin));
|
||||||
|
plugin.plugin_slot = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ void mjCMesh::LoadSDF() {
|
|||||||
|
|
||||||
mjCPlugin* plugin_instance = (mjCPlugin*)plugin.instance;
|
mjCPlugin* plugin_instance = (mjCPlugin*)plugin.instance;
|
||||||
model->ResolvePlugin(this, plugin_name, plugin_instance_name, &plugin_instance);
|
model->ResolvePlugin(this, plugin_name, plugin_instance_name, &plugin_instance);
|
||||||
const mjpPlugin* pplugin = mjp_getPluginAtSlot(plugin_instance->plugin_slot);
|
const mjpPlugin* pplugin = mjp_getPluginAtSlot(plugin_instance->spec.plugin_slot);
|
||||||
if (!(pplugin->capabilityflags & mjPLUGIN_SDF)) {
|
if (!(pplugin->capabilityflags & mjPLUGIN_SDF)) {
|
||||||
throw mjCError(this, "plugin '%s' does not support signed distance fields", pplugin->name);
|
throw mjCError(this, "plugin '%s' does not support signed distance fields", pplugin->name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3044,7 +3044,7 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) {
|
|||||||
{
|
{
|
||||||
int adr = 0;
|
int adr = 0;
|
||||||
for (int i = 0; i < nplugin; ++i) {
|
for (int i = 0; i < nplugin; ++i) {
|
||||||
m->plugin[i] = plugins[i]->plugin_slot;
|
m->plugin[i] = plugins[i]->spec.plugin_slot;
|
||||||
const int size = plugins[i]->flattened_attributes.size();
|
const int size = plugins[i]->flattened_attributes.size();
|
||||||
std::memcpy(m->plugin_attr + adr,
|
std::memcpy(m->plugin_attr + adr,
|
||||||
plugins[i]->flattened_attributes.data(), size);
|
plugins[i]->flattened_attributes.data(), size);
|
||||||
@@ -3575,8 +3575,8 @@ void mjCModel::ResolvePlugin(mjCBase* obj, const std::string& plugin_name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// implicit plugin instance
|
// implicit plugin instance
|
||||||
if (*plugin_instance && (*plugin_instance)->plugin_slot == -1) {
|
if (*plugin_instance && (*plugin_instance)->spec.plugin_slot == -1) {
|
||||||
(*plugin_instance)->plugin_slot = plugin_slot;
|
(*plugin_instance)->spec.plugin_slot = plugin_slot;
|
||||||
(*plugin_instance)->parent = obj;
|
(*plugin_instance)->parent = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3588,10 +3588,10 @@ void mjCModel::ResolvePlugin(mjCBase* obj, const std::string& plugin_name,
|
|||||||
throw mjCError(
|
throw mjCError(
|
||||||
obj, "unrecognized name '%s' for plugin instance", plugin_instance_name.c_str());
|
obj, "unrecognized name '%s' for plugin instance", plugin_instance_name.c_str());
|
||||||
}
|
}
|
||||||
if (plugin_slot != -1 && plugin_slot != (*plugin_instance)->plugin_slot) {
|
if (plugin_slot != -1 && plugin_slot != (*plugin_instance)->spec.plugin_slot) {
|
||||||
throw mjCError(
|
throw mjCError(
|
||||||
obj, "'plugin' attribute does not match that of the instance");
|
obj, "'plugin' attribute does not match that of the instance");
|
||||||
}
|
}
|
||||||
plugin_slot = (*plugin_instance)->plugin_slot;
|
plugin_slot = (*plugin_instance)->spec.plugin_slot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-19
@@ -544,13 +544,6 @@ mjCBase::mjCBase() {
|
|||||||
model = 0;
|
model = 0;
|
||||||
def = 0;
|
def = 0;
|
||||||
frame = nullptr;
|
frame = nullptr;
|
||||||
|
|
||||||
// plugin variables
|
|
||||||
mjm_defaultPlugin(plugin);
|
|
||||||
plugin_name = "";
|
|
||||||
plugin_instance_name = "";
|
|
||||||
plugin.name = (mjString)&plugin_name;
|
|
||||||
plugin.instance_name = (mjString)&plugin_instance_name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1193,7 +1186,7 @@ void mjCBody::Compile(void) {
|
|||||||
|
|
||||||
mjCPlugin** plugin_instance = (mjCPlugin**)&plugin.instance;
|
mjCPlugin** plugin_instance = (mjCPlugin**)&plugin.instance;
|
||||||
model->ResolvePlugin(this, plugin_name, plugin_instance_name, plugin_instance);
|
model->ResolvePlugin(this, plugin_name, plugin_instance_name, plugin_instance);
|
||||||
const mjpPlugin* pplugin = mjp_getPluginAtSlot((*plugin_instance)->plugin_slot);
|
const mjpPlugin* pplugin = mjp_getPluginAtSlot((*plugin_instance)->spec.plugin_slot);
|
||||||
if (!(pplugin->capabilityflags & mjPLUGIN_PASSIVE)) {
|
if (!(pplugin->capabilityflags & mjPLUGIN_PASSIVE)) {
|
||||||
throw mjCError(this, "plugin '%s' does not support passive forces", pplugin->name);
|
throw mjCError(this, "plugin '%s' does not support passive forces", pplugin->name);
|
||||||
}
|
}
|
||||||
@@ -2047,7 +2040,7 @@ void mjCGeom::Compile(void) {
|
|||||||
|
|
||||||
mjCPlugin** plugin_instance = (mjCPlugin**)&plugin.instance;
|
mjCPlugin** plugin_instance = (mjCPlugin**)&plugin.instance;
|
||||||
model->ResolvePlugin(this, plugin_name, plugin_instance_name, plugin_instance);
|
model->ResolvePlugin(this, plugin_name, plugin_instance_name, plugin_instance);
|
||||||
const mjpPlugin* pplugin = mjp_getPluginAtSlot((*plugin_instance)->plugin_slot);
|
const mjpPlugin* pplugin = mjp_getPluginAtSlot((*plugin_instance)->spec.plugin_slot);
|
||||||
if (!(pplugin->capabilityflags & mjPLUGIN_SDF)) {
|
if (!(pplugin->capabilityflags & mjPLUGIN_SDF)) {
|
||||||
throw mjCError(this, "plugin '%s' does not support sign distance fields", pplugin->name);
|
throw mjCError(this, "plugin '%s' does not support sign distance fields", pplugin->name);
|
||||||
}
|
}
|
||||||
@@ -4487,7 +4480,7 @@ void mjCActuator::Compile(void) {
|
|||||||
|
|
||||||
mjCPlugin** plugin_instance = (mjCPlugin**)&plugin.instance;
|
mjCPlugin** plugin_instance = (mjCPlugin**)&plugin.instance;
|
||||||
model->ResolvePlugin(this, plugin_name, plugin_instance_name, plugin_instance);
|
model->ResolvePlugin(this, plugin_name, plugin_instance_name, plugin_instance);
|
||||||
const mjpPlugin* pplugin = mjp_getPluginAtSlot((*plugin_instance)->plugin_slot);
|
const mjpPlugin* pplugin = mjp_getPluginAtSlot((*plugin_instance)->spec.plugin_slot);
|
||||||
if (!(pplugin->capabilityflags & mjPLUGIN_ACTUATOR)) {
|
if (!(pplugin->capabilityflags & mjPLUGIN_ACTUATOR)) {
|
||||||
throw mjCError(this, "plugin '%s' does not support actuators", pplugin->name);
|
throw mjCError(this, "plugin '%s' does not support actuators", pplugin->name);
|
||||||
}
|
}
|
||||||
@@ -4921,7 +4914,7 @@ void mjCSensor::Compile(void) {
|
|||||||
{
|
{
|
||||||
mjCPlugin** plugin_instance = (mjCPlugin**)&plugin.instance;
|
mjCPlugin** plugin_instance = (mjCPlugin**)&plugin.instance;
|
||||||
model->ResolvePlugin(this, plugin_name, plugin_instance_name, plugin_instance);
|
model->ResolvePlugin(this, plugin_name, plugin_instance_name, plugin_instance);
|
||||||
const mjpPlugin* pplugin = mjp_getPluginAtSlot((*plugin_instance)->plugin_slot);
|
const mjpPlugin* pplugin = mjp_getPluginAtSlot((*plugin_instance)->spec.plugin_slot);
|
||||||
if (!(pplugin->capabilityflags & mjPLUGIN_SENSOR)) {
|
if (!(pplugin->capabilityflags & mjPLUGIN_SENSOR)) {
|
||||||
throw mjCError(this, "plugin '%s' does not support sensors", pplugin->name);
|
throw mjCError(this, "plugin '%s' does not support sensors", pplugin->name);
|
||||||
}
|
}
|
||||||
@@ -5332,24 +5325,24 @@ void mjCKey::Compile(const mjModel* m) {
|
|||||||
// initialize defaults
|
// initialize defaults
|
||||||
mjCPlugin::mjCPlugin(mjCModel* _model) {
|
mjCPlugin::mjCPlugin(mjCModel* _model) {
|
||||||
name = "";
|
name = "";
|
||||||
plugin_slot = -1;
|
nstate = -1;
|
||||||
nstate = 0;
|
|
||||||
parent = this;
|
parent = this;
|
||||||
model = _model;
|
model = _model;
|
||||||
|
name.clear();
|
||||||
|
instance_name.clear();
|
||||||
|
|
||||||
// public interface
|
// public interface
|
||||||
mjm_defaultPlugin(plugin);
|
mjm_defaultPlugin(spec);
|
||||||
plugin_name = "";
|
spec.name = (mjString)&name;
|
||||||
plugin_instance_name = "";
|
spec.instance_name = (mjString)&instance_name;
|
||||||
plugin.name = (mjString)&plugin_name;
|
spec.info = (mjString)&info;
|
||||||
plugin.instance_name = (mjString)&plugin_instance_name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// compiler
|
// compiler
|
||||||
void mjCPlugin::Compile(void) {
|
void mjCPlugin::Compile(void) {
|
||||||
const mjpPlugin* plugin = mjp_getPluginAtSlot(this->plugin_slot);
|
const mjpPlugin* plugin = mjp_getPluginAtSlot(spec.plugin_slot);
|
||||||
|
|
||||||
// concatenate all of the plugin's attribute values (as null-terminated strings) into
|
// concatenate all of the plugin's attribute values (as null-terminated strings) into
|
||||||
// flattened_attributes, in the order declared in the mjpPlugin
|
// flattened_attributes, in the order declared in the mjpPlugin
|
||||||
|
|||||||
+13
-10
@@ -173,10 +173,6 @@ class mjCBase {
|
|||||||
mjCModel* model; // pointer to model that created object
|
mjCModel* model; // pointer to model that created object
|
||||||
mjCFrame* frame; // pointer to frame transformation
|
mjCFrame* frame; // pointer to frame transformation
|
||||||
|
|
||||||
// plugin support
|
|
||||||
mjmPlugin plugin;
|
|
||||||
std::string plugin_name;
|
|
||||||
std::string plugin_instance_name;
|
|
||||||
protected:
|
protected:
|
||||||
mjCBase(); // constructor
|
mjCBase(); // constructor
|
||||||
virtual ~mjCBase() = default; // destructor
|
virtual ~mjCBase() = default; // destructor
|
||||||
@@ -233,7 +229,6 @@ class mjCBody : public mjCBase, private mjmBody {
|
|||||||
using mjCBase::name;
|
using mjCBase::name;
|
||||||
using mjCBase::classname;
|
using mjCBase::classname;
|
||||||
using mjCBase::info;
|
using mjCBase::info;
|
||||||
using mjCBase::plugin;
|
|
||||||
|
|
||||||
// used by mjXWriter and mjCModel
|
// used by mjXWriter and mjCModel
|
||||||
const std::vector<double>& get_userdata() { return userdata_; }
|
const std::vector<double>& get_userdata() { return userdata_; }
|
||||||
@@ -278,6 +273,8 @@ class mjCBody : public mjCBase, private mjmBody {
|
|||||||
void PointToLocal(void);
|
void PointToLocal(void);
|
||||||
|
|
||||||
// variable-size data
|
// variable-size data
|
||||||
|
std::string plugin_name;
|
||||||
|
std::string plugin_instance_name;
|
||||||
std::vector<double> userdata_;
|
std::vector<double> userdata_;
|
||||||
std::vector<double> spec_userdata_;
|
std::vector<double> spec_userdata_;
|
||||||
};
|
};
|
||||||
@@ -415,6 +412,8 @@ class mjCGeom : public mjCBase, private mjmGeom {
|
|||||||
mjtNum fluid[mjNFLUID]; // compile-time fluid-interaction parameters
|
mjtNum fluid[mjNFLUID]; // compile-time fluid-interaction parameters
|
||||||
|
|
||||||
// variable-size data
|
// variable-size data
|
||||||
|
std::string plugin_name;
|
||||||
|
std::string plugin_instance_name;
|
||||||
std::string hfieldname_;
|
std::string hfieldname_;
|
||||||
std::string meshname_;
|
std::string meshname_;
|
||||||
std::string material_;
|
std::string material_;
|
||||||
@@ -427,7 +426,6 @@ class mjCGeom : public mjCBase, private mjmGeom {
|
|||||||
// inherited
|
// inherited
|
||||||
using mjCBase::classname;
|
using mjCBase::classname;
|
||||||
using mjCBase::info;
|
using mjCBase::info;
|
||||||
using mjCBase::plugin;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -625,7 +623,6 @@ class mjCMesh: public mjCBase, private mjmMesh {
|
|||||||
mjmMesh spec;
|
mjmMesh spec;
|
||||||
using mjCBase::name;
|
using mjCBase::name;
|
||||||
using mjCBase::classname;
|
using mjCBase::classname;
|
||||||
using mjCBase::plugin;
|
|
||||||
using mjCBase::info;
|
using mjCBase::info;
|
||||||
|
|
||||||
void CopyFromSpec(void);
|
void CopyFromSpec(void);
|
||||||
@@ -687,6 +684,9 @@ class mjCMesh: public mjCBase, private mjmMesh {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// variable size attributes
|
// variable size attributes
|
||||||
|
std::string plugin_name;
|
||||||
|
std::string plugin_instance_name;
|
||||||
|
|
||||||
std::string content_type_; // content type of file
|
std::string content_type_; // content type of file
|
||||||
std::string file_; // mesh file
|
std::string file_; // mesh file
|
||||||
std::vector<float> uservert_; // user vertex data
|
std::vector<float> uservert_; // user vertex data
|
||||||
@@ -1164,7 +1164,7 @@ class mjCPlugin : public mjCBase {
|
|||||||
friend class mjXWriter;
|
friend class mjXWriter;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int plugin_slot; // global registered slot number of the plugin
|
mjmPlugin spec;
|
||||||
int nstate; // state size for the plugin instance
|
int nstate; // state size for the plugin instance
|
||||||
mjCBase* parent; // parent object (only used when generating error message)
|
mjCBase* parent; // parent object (only used when generating error message)
|
||||||
std::map<std::string, std::string, std::less<>> config_attribs; // raw config attributes from XML
|
std::map<std::string, std::string, std::less<>> config_attribs; // raw config attributes from XML
|
||||||
@@ -1173,6 +1173,7 @@ class mjCPlugin : public mjCBase {
|
|||||||
private:
|
private:
|
||||||
mjCPlugin(mjCModel*); // constructor
|
mjCPlugin(mjCModel*); // constructor
|
||||||
void Compile(void); // compiler
|
void Compile(void); // compiler
|
||||||
|
std::string instance_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -1190,7 +1191,6 @@ class mjCActuator : public mjCBase, private mjmActuator {
|
|||||||
using mjCBase::name;
|
using mjCBase::name;
|
||||||
using mjCBase::classname;
|
using mjCBase::classname;
|
||||||
using mjCBase::info;
|
using mjCBase::info;
|
||||||
using mjCBase::plugin;
|
|
||||||
|
|
||||||
// used by mjXWriter and mjCModel
|
// used by mjXWriter and mjCModel
|
||||||
const std::vector<double>& get_userdata() { return userdata_; }
|
const std::vector<double>& get_userdata() { return userdata_; }
|
||||||
@@ -1211,6 +1211,8 @@ class mjCActuator : public mjCBase, private mjmActuator {
|
|||||||
int trnid[2]; // id of transmission target
|
int trnid[2]; // id of transmission target
|
||||||
|
|
||||||
// variable-size data
|
// variable-size data
|
||||||
|
std::string plugin_name;
|
||||||
|
std::string plugin_instance_name;
|
||||||
std::string target_;
|
std::string target_;
|
||||||
std::string slidersite_;
|
std::string slidersite_;
|
||||||
std::string refsite_;
|
std::string refsite_;
|
||||||
@@ -1236,7 +1238,6 @@ class mjCSensor : public mjCBase, private mjmSensor {
|
|||||||
using mjCBase::name;
|
using mjCBase::name;
|
||||||
using mjCBase::classname;
|
using mjCBase::classname;
|
||||||
using mjCBase::info;
|
using mjCBase::info;
|
||||||
using mjCBase::plugin;
|
|
||||||
|
|
||||||
// used by mjXWriter and mjCModel
|
// used by mjXWriter and mjCModel
|
||||||
const std::vector<double>& get_userdata() { return userdata_; }
|
const std::vector<double>& get_userdata() { return userdata_; }
|
||||||
@@ -1253,6 +1254,8 @@ class mjCSensor : public mjCBase, private mjmSensor {
|
|||||||
int refid; // id of reference frame
|
int refid; // id of reference frame
|
||||||
|
|
||||||
// variable-size data
|
// variable-size data
|
||||||
|
std::string plugin_name;
|
||||||
|
std::string plugin_instance_name;
|
||||||
std::string objname_;
|
std::string objname_;
|
||||||
std::string refname_;
|
std::string refname_;
|
||||||
std::vector<double> userdata_;
|
std::vector<double> userdata_;
|
||||||
|
|||||||
@@ -40,7 +40,6 @@
|
|||||||
#include "user/user_composite.h"
|
#include "user/user_composite.h"
|
||||||
#include "user/user_flexcomp.h"
|
#include "user/user_flexcomp.h"
|
||||||
#include "user/user_model.h"
|
#include "user/user_model.h"
|
||||||
#include "user/user_objects.h"
|
|
||||||
#include "user/user_util.h"
|
#include "user/user_util.h"
|
||||||
#include "xml/xml_base.h"
|
#include "xml/xml_base.h"
|
||||||
#include "xml/xml_util.h"
|
#include "xml/xml_util.h"
|
||||||
@@ -50,7 +49,7 @@ using std::string;
|
|||||||
using std::vector;
|
using std::vector;
|
||||||
using tinyxml2::XMLElement;
|
using tinyxml2::XMLElement;
|
||||||
|
|
||||||
void ReadPluginConfigs(tinyxml2::XMLElement* elem, mjCPlugin* pp) {
|
void ReadPluginConfigs(tinyxml2::XMLElement* elem, mjmPlugin* p) {
|
||||||
std::map<std::string, std::string, std::less<>> config_attribs;
|
std::map<std::string, std::string, std::less<>> config_attribs;
|
||||||
XMLElement* child = FirstChildElement(elem);
|
XMLElement* child = FirstChildElement(elem);
|
||||||
while (child) {
|
while (child) {
|
||||||
@@ -68,12 +67,12 @@ void ReadPluginConfigs(tinyxml2::XMLElement* elem, mjCPlugin* pp) {
|
|||||||
child = NextSiblingElement(child);
|
child = NextSiblingElement(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pp && !config_attribs.empty()) {
|
if (!p && !config_attribs.empty()) {
|
||||||
throw mjXError(elem,
|
throw mjXError(elem,
|
||||||
"plugin configuration attributes cannot be used in an "
|
"plugin configuration attributes cannot be used in an "
|
||||||
"element that references a predefined plugin instance");
|
"element that references a predefined plugin instance");
|
||||||
} else if (pp) {
|
} else if (p) {
|
||||||
pp->config_attribs = std::move(config_attribs);
|
mjm_setPluginAttributes(p, &config_attribs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
@@ -2276,10 +2275,6 @@ void mjXReader::OneComposite(XMLElement* elem, mjmBody* pbody, mjmDefault* def)
|
|||||||
XMLElement* eplugin = FirstChildElement(elem, "plugin");
|
XMLElement* eplugin = FirstChildElement(elem, "plugin");
|
||||||
if (eplugin) {
|
if (eplugin) {
|
||||||
OnePlugin(eplugin, &comp.plugin);
|
OnePlugin(eplugin, &comp.plugin);
|
||||||
if (comp.plugin_instance_name.empty()) {
|
|
||||||
comp.plugin_instance_name = "composite" + comp.prefix;
|
|
||||||
((mjCPlugin*)comp.plugin.instance)->name = comp.plugin_instance_name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cable
|
// cable
|
||||||
@@ -2602,10 +2597,6 @@ void mjXReader::OneFlexcomp(XMLElement* elem, mjmBody* pbody) {
|
|||||||
XMLElement* eplugin = FirstChildElement(elem, "plugin");
|
XMLElement* eplugin = FirstChildElement(elem, "plugin");
|
||||||
if (eplugin) {
|
if (eplugin) {
|
||||||
OnePlugin(eplugin, &fcomp.plugin);
|
OnePlugin(eplugin, &fcomp.plugin);
|
||||||
if (fcomp.plugin_instance_name.empty()) {
|
|
||||||
fcomp.plugin_instance_name = "flexcomp_" + fcomp.name;
|
|
||||||
((mjCPlugin*)fcomp.plugin.instance)->name = fcomp.plugin_instance_name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// make flexcomp
|
// make flexcomp
|
||||||
@@ -2631,7 +2622,7 @@ void mjXReader::OnePlugin(XMLElement* elem, mjmPlugin* plugin) {
|
|||||||
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)->instance;
|
plugin->instance = mjm_addPlugin(&model->spec)->instance;
|
||||||
ReadPluginConfigs(elem, (mjCPlugin*)plugin->instance);
|
ReadPluginConfigs(elem, plugin);
|
||||||
} else {
|
} else {
|
||||||
model->hasImplicitPluginElem = true;
|
model->hasImplicitPluginElem = true;
|
||||||
}
|
}
|
||||||
@@ -2789,15 +2780,16 @@ 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)->instance;
|
string name;
|
||||||
GetXMLPos(child, pp);
|
mjmPlugin* p = mjm_addPlugin(&model->spec);
|
||||||
ReadAttrTxt(child, "name", pp->name, /* required = */ true);
|
mjm_setString(p->info, ("line = " + std::to_string(elem->GetLineNum())).c_str());
|
||||||
if (pp->name.empty()) {
|
ReadAttrTxt(child, "name", name, /* required = */ true);
|
||||||
|
mjm_setString(p->name, name.c_str());
|
||||||
|
if (!p->name) {
|
||||||
throw mjXError(child, "plugin instance must have a name");
|
throw mjXError(child, "plugin instance must have a name");
|
||||||
}
|
}
|
||||||
ReadPluginConfigs(child, pp);
|
ReadPluginConfigs(child, p);
|
||||||
pp->plugin_slot = plugin_slot;
|
p->plugin_slot = plugin_slot;
|
||||||
pp->nstate = -1; // actual value to be filled in by the plugin later
|
|
||||||
}
|
}
|
||||||
child = NextSiblingElement(child);
|
child = NextSiblingElement(child);
|
||||||
}
|
}
|
||||||
@@ -4034,10 +4026,6 @@ mjmDefault* mjXReader::GetClass(XMLElement* section) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// get xml position
|
|
||||||
void mjXReader::GetXMLPos(XMLElement* elem, mjCBase* obj) {
|
|
||||||
obj->info = "line = " + std::to_string(elem->GetLineNum());
|
|
||||||
}
|
|
||||||
|
|
||||||
// return true if c is a directory path separator (i.e. '/' or '\' on windows)
|
// return true if c is a directory path separator (i.e. '/' or '\' on windows)
|
||||||
static bool IsSeperator(char c) {
|
static bool IsSeperator(char c) {
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
#include <mujoco/mujoco.h>
|
#include <mujoco/mujoco.h>
|
||||||
#include "user/user_api.h"
|
#include "user/user_api.h"
|
||||||
#include "user/user_model.h"
|
#include "user/user_model.h"
|
||||||
#include "user/user_objects.h"
|
|
||||||
#include "xml/xml_base.h"
|
#include "xml/xml_base.h"
|
||||||
#include "xml/xml_util.h"
|
#include "xml/xml_util.h"
|
||||||
|
|
||||||
@@ -86,7 +85,6 @@ class mjXReader : public mjXBase {
|
|||||||
|
|
||||||
mjXSchema schema; // schema used for validation
|
mjXSchema schema; // schema used for validation
|
||||||
mjmDefault* GetClass(tinyxml2::XMLElement* section); // get default class name
|
mjmDefault* GetClass(tinyxml2::XMLElement* section); // get default class name
|
||||||
static void GetXMLPos(tinyxml2::XMLElement* elem, mjCBase* obj); // get xml position
|
|
||||||
|
|
||||||
bool readingdefaults; // true while reading defaults
|
bool readingdefaults; // true while reading defaults
|
||||||
|
|
||||||
|
|||||||
@@ -412,7 +412,7 @@ void mjXWriter::OneGeom(XMLElement* elem, mjCGeom* pgeom, mjCDef* def) {
|
|||||||
|
|
||||||
// write plugin
|
// write plugin
|
||||||
if (pgeom->plugin.active) {
|
if (pgeom->plugin.active) {
|
||||||
OnePlugin(InsertEnd(elem, "plugin"), pgeom);
|
OnePlugin(InsertEnd(elem, "plugin"), &pgeom->plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -702,7 +702,7 @@ void mjXWriter::OneActuator(XMLElement* elem, mjCActuator* pact, mjCDef* def) {
|
|||||||
|
|
||||||
// plugins: write config attributes
|
// plugins: write config attributes
|
||||||
if (pact->plugin.active) {
|
if (pact->plugin.active) {
|
||||||
OnePlugin(elem, pact);
|
OnePlugin(elem, &pact->plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// non-plugins: write actuator parameters
|
// non-plugins: write actuator parameters
|
||||||
@@ -731,21 +731,21 @@ void mjXWriter::OneActuator(XMLElement* elem, mjCActuator* pact, mjCDef* def) {
|
|||||||
|
|
||||||
|
|
||||||
// write plugin
|
// write plugin
|
||||||
void mjXWriter::OnePlugin(XMLElement* elem, mjCBase* object) {
|
void mjXWriter::OnePlugin(XMLElement* elem, mjmPlugin* plugin) {
|
||||||
const std::string instance_name = std::string(mjm_getString(object->plugin.instance_name));
|
const std::string instance_name = std::string(mjm_getString(plugin->instance_name));
|
||||||
const std::string plugin_name = std::string(mjm_getString(object->plugin.name));
|
const std::string plugin_name = std::string(mjm_getString(plugin->name));
|
||||||
if (!instance_name.empty()) {
|
if (!instance_name.empty()) {
|
||||||
WriteAttrTxt(elem, "instance", instance_name);
|
WriteAttrTxt(elem, "instance", instance_name);
|
||||||
} else {
|
} else {
|
||||||
WriteAttrTxt(elem, "plugin", plugin_name);
|
WriteAttrTxt(elem, "plugin", plugin_name);
|
||||||
const mjpPlugin* plugin = mjp_getPluginAtSlot(
|
const mjpPlugin* pplugin = mjp_getPluginAtSlot(
|
||||||
((mjCPlugin*)object->plugin.instance)->plugin_slot);
|
((mjCPlugin*)plugin->instance)->spec.plugin_slot);
|
||||||
const char* c = &((mjCPlugin*)object->plugin.instance)->flattened_attributes[0];
|
const char* c = &((mjCPlugin*)plugin->instance)->flattened_attributes[0];
|
||||||
for (int i = 0; i < plugin->nattribute; ++i) {
|
for (int i = 0; i < pplugin->nattribute; ++i) {
|
||||||
std::string value(c);
|
std::string value(c);
|
||||||
if (!value.empty()) {
|
if (!value.empty()) {
|
||||||
XMLElement* config_elem = InsertEnd(elem, "config");
|
XMLElement* config_elem = InsertEnd(elem, "config");
|
||||||
WriteAttrTxt(config_elem, "key", plugin->attributes[i]);
|
WriteAttrTxt(config_elem, "key", pplugin->attributes[i]);
|
||||||
WriteAttrTxt(config_elem, "value", value);
|
WriteAttrTxt(config_elem, "value", value);
|
||||||
c += value.size();
|
c += value.size();
|
||||||
}
|
}
|
||||||
@@ -1229,7 +1229,7 @@ void mjXWriter::Extension(XMLElement* root) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if we need to open a new <plugin> section
|
// check if we need to open a new <plugin> section
|
||||||
const mjpPlugin* plugin = mjp_getPluginAtSlot(pp->plugin_slot);
|
const mjpPlugin* plugin = mjp_getPluginAtSlot(pp->spec.plugin_slot);
|
||||||
if (plugin != last_plugin) {
|
if (plugin != last_plugin) {
|
||||||
plugin_elem = InsertEnd(section, "plugin");
|
plugin_elem = InsertEnd(section, "plugin");
|
||||||
WriteAttrTxt(plugin_elem, "plugin", plugin->name);
|
WriteAttrTxt(plugin_elem, "plugin", plugin->name);
|
||||||
@@ -1406,7 +1406,7 @@ void mjXWriter::Asset(XMLElement* root) {
|
|||||||
if (pmesh->plugin.active) {
|
if (pmesh->plugin.active) {
|
||||||
elem = InsertEnd(section, "mesh");
|
elem = InsertEnd(section, "mesh");
|
||||||
WriteAttrTxt(elem, "name", pmesh->name);
|
WriteAttrTxt(elem, "name", pmesh->name);
|
||||||
OnePlugin(InsertEnd(elem, "plugin"), pmesh);
|
OnePlugin(InsertEnd(elem, "plugin"), &pmesh->plugin);
|
||||||
} else{
|
} else{
|
||||||
elem = InsertEnd(section, "mesh");
|
elem = InsertEnd(section, "mesh");
|
||||||
OneMesh(elem, pmesh, pmesh->def);
|
OneMesh(elem, pmesh, pmesh->def);
|
||||||
@@ -1506,7 +1506,7 @@ void mjXWriter::Body(XMLElement* elem, mjCBody* body) {
|
|||||||
|
|
||||||
// write plugin
|
// write plugin
|
||||||
if (body->plugin.active) {
|
if (body->plugin.active) {
|
||||||
OnePlugin(InsertEnd(elem, "plugin"), body);
|
OnePlugin(InsertEnd(elem, "plugin"), &body->plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// write child bodies recursively
|
// write child bodies recursively
|
||||||
@@ -1904,7 +1904,7 @@ void mjXWriter::Sensor(XMLElement* root) {
|
|||||||
WriteAttrTxt(elem, "objtype", mju_type2Str(psen->objtype));
|
WriteAttrTxt(elem, "objtype", mju_type2Str(psen->objtype));
|
||||||
WriteAttrTxt(elem, "objname", psen->get_objname());
|
WriteAttrTxt(elem, "objname", psen->get_objname());
|
||||||
}
|
}
|
||||||
OnePlugin(elem, psen);
|
OnePlugin(elem, &psen->plugin);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// user-defined sensor
|
// user-defined sensor
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ class mjXWriter : public mjXBase {
|
|||||||
void OneEquality(tinyxml2::XMLElement* elem, mjCEquality* pequality, mjCDef* def);
|
void OneEquality(tinyxml2::XMLElement* elem, mjCEquality* pequality, mjCDef* def);
|
||||||
void OneTendon(tinyxml2::XMLElement* elem, mjCTendon* ptendon, mjCDef* def);
|
void OneTendon(tinyxml2::XMLElement* elem, mjCTendon* ptendon, mjCDef* def);
|
||||||
void OneActuator(tinyxml2::XMLElement* elem, mjCActuator* pactuator, mjCDef* def);
|
void OneActuator(tinyxml2::XMLElement* elem, mjCActuator* pactuator, mjCDef* def);
|
||||||
void OnePlugin(tinyxml2::XMLElement* elem, mjCBase* object);
|
void OnePlugin(tinyxml2::XMLElement* elem, mjmPlugin* plugin);
|
||||||
|
|
||||||
bool writingdefaults; // true during defaults write
|
bool writingdefaults; // true during defaults write
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user