Encapsulate mjCMesh data, apply Google C++ naming convention to class members (See https://google.github.io/styleguide/cppguide.html#Variable_Names), and fix a couple of typos.
PiperOrigin-RevId: 553129088 Change-Id: Ic515154220af472f4fc90ca9ade92d86b205cc94
This commit is contained in:
@@ -1155,7 +1155,6 @@ void mjXReader::Size(XMLElement* section, mjCModel* mod) {
|
||||
|
||||
ReadAttrInt(section, "nuser_sensor", &mod->nuser_sensor);
|
||||
if (mod->nuser_sensor < -1) throw mjXError(section, "nuser_sensor must be >= -1");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1187,26 +1186,27 @@ void mjXReader::OneMesh(XMLElement* elem, mjCMesh* pmesh) {
|
||||
// read attributes
|
||||
ReadAttrTxt(elem, "name", pmesh->name);
|
||||
ReadAttrTxt(elem, "class", pmesh->classname);
|
||||
ReadAttrTxt(elem, "content_type", pmesh->content_type);
|
||||
ReadAttrTxt(elem, "file", pmesh->file);
|
||||
ReadAttr(elem, "refpos", 3, pmesh->refpos, text);
|
||||
ReadAttr(elem, "refquat", 4, pmesh->refquat, text);
|
||||
ReadAttr(elem, "scale", 3, pmesh->scale, text);
|
||||
pmesh->set_content_type(ReadAttrStr(elem, "content_type"));
|
||||
pmesh->set_file(ReadAttrStr(elem, "file"));
|
||||
pmesh->set_refpos(ReadAttrArr<double, 3>(elem, "refpos"));
|
||||
pmesh->set_refquat(ReadAttrArr<double, 4>(elem, "refquat"));
|
||||
pmesh->set_scale(ReadAttrArr<double, 3>(elem, "scale"));
|
||||
|
||||
if (MapValue(elem, "smoothnormal", &n, bool_map, 2)) {
|
||||
pmesh->smoothnormal = (n==1);
|
||||
pmesh->set_smoothnormal((n==1));
|
||||
}
|
||||
|
||||
// read user vertex data
|
||||
if (ReadAttrTxt(elem, "vertex", text)) String2Vector(text, pmesh->uservert);
|
||||
pmesh->set_uservert(ReadAttrVec<float>(elem, "vertex"));
|
||||
|
||||
// read user normal data
|
||||
if (ReadAttrTxt(elem, "normal", text)) String2Vector(text, pmesh->usernormal);
|
||||
pmesh->set_usernormal(ReadAttrVec<float>(elem, "normal"));
|
||||
|
||||
// read user texcoord data
|
||||
if (ReadAttrTxt(elem, "texcoord", text)) String2Vector(text, pmesh->usertexcoord);
|
||||
pmesh->set_usertexcoord(ReadAttrVec<float>(elem, "texcoord"));
|
||||
|
||||
// read user face data
|
||||
if (ReadAttrTxt(elem, "face", text)) String2Vector(text, pmesh->userface);
|
||||
pmesh->set_userface(ReadAttrVec<int>(elem, "face"));
|
||||
|
||||
GetXMLPos(elem, pmesh);
|
||||
}
|
||||
|
||||
@@ -90,39 +90,39 @@ void mjXWriter::OneMesh(XMLElement* elem, mjCMesh* pmesh, mjCDef* def) {
|
||||
if (!writingdefaults) {
|
||||
WriteAttrTxt(elem, "name", pmesh->name);
|
||||
WriteAttrTxt(elem, "class", pmesh->classname);
|
||||
WriteAttrTxt(elem, "content_type", pmesh->content_type);
|
||||
WriteAttrTxt(elem, "file", pmesh->file);
|
||||
WriteAttrTxt(elem, "content_type", pmesh->content_type());
|
||||
WriteAttrTxt(elem, "file", pmesh->file());
|
||||
|
||||
// write vertex data
|
||||
if (!pmesh->uservert.empty()) {
|
||||
Vector2String(text, pmesh->uservert);
|
||||
if (!pmesh->uservert().empty()) {
|
||||
Vector2String(text, pmesh->uservert());
|
||||
WriteAttrTxt(elem, "vertex", text);
|
||||
}
|
||||
|
||||
// write normal data
|
||||
if (!pmesh->usernormal.empty()) {
|
||||
Vector2String(text, pmesh->usernormal);
|
||||
if (!pmesh->usernormal().empty()) {
|
||||
Vector2String(text, pmesh->usernormal());
|
||||
WriteAttrTxt(elem, "normal", text);
|
||||
}
|
||||
|
||||
// write texcoord data
|
||||
if (!pmesh->usertexcoord.empty()) {
|
||||
Vector2String(text, pmesh->usertexcoord);
|
||||
if (!pmesh->usertexcoord().empty()) {
|
||||
Vector2String(text, pmesh->usertexcoord());
|
||||
WriteAttrTxt(elem, "texcoord", text);
|
||||
}
|
||||
|
||||
// write face data
|
||||
if (!pmesh->userface.empty()) {
|
||||
Vector2String(text, pmesh->userface);
|
||||
if (!pmesh->userface().empty()) {
|
||||
Vector2String(text, pmesh->userface());
|
||||
WriteAttrTxt(elem, "face", text);
|
||||
}
|
||||
}
|
||||
|
||||
// defaults and regular
|
||||
WriteAttr(elem, "refpos", 3, pmesh->refpos, def->mesh.refpos);
|
||||
WriteAttr(elem, "refquat", 4, pmesh->refquat, def->mesh.refquat);
|
||||
WriteAttr(elem, "scale", 3, pmesh->scale, def->mesh.scale);
|
||||
WriteAttrKey(elem, "smoothnormal", bool_map, 2, pmesh->smoothnormal, def->mesh.smoothnormal);
|
||||
WriteAttr(elem, "refpos", 3, pmesh->refpos(), def->mesh.refpos());
|
||||
WriteAttr(elem, "refquat", 4, pmesh->refquat(), def->mesh.refquat());
|
||||
WriteAttr(elem, "scale", 3, pmesh->scale(), def->mesh.scale());
|
||||
WriteAttrKey(elem, "smoothnormal", bool_map, 2, pmesh->smoothnormal(), def->mesh.smoothnormal());
|
||||
}
|
||||
|
||||
|
||||
|
||||
+9
-8
@@ -542,10 +542,11 @@ mjCGeom* mjXURDF::Geom(XMLElement* geom_elem, mjCBody* pbody, bool collision) {
|
||||
// mesh
|
||||
else if ((temp = FindSubElem(elem, "mesh"))) {
|
||||
// set geom type and read mesh attributes
|
||||
double meshscale[3] = {1, 1, 1};
|
||||
pgeom->type = mjGEOM_MESH;
|
||||
ReadAttrTxt(temp, "filename", meshfile, true);
|
||||
ReadAttr(temp, "scale", 3, meshscale, text);
|
||||
meshfile = ReadAttrStr(temp, "filename", true).value();
|
||||
std::array<double, 3> default_meshscale = {1, 1, 1};
|
||||
std::array<double, 3> meshscale = ReadAttrArr<double, 3>(temp, "scale")
|
||||
.value_or(default_meshscale);
|
||||
|
||||
// strip file name if necessary
|
||||
if (model->strippath) {
|
||||
@@ -565,18 +566,18 @@ mjCGeom* mjXURDF::Geom(XMLElement* geom_elem, mjCBody* pbody, bool collision) {
|
||||
}
|
||||
|
||||
// exists with different scale: append name with '1', create
|
||||
else if (pmesh->scale[0]!=meshscale[0] ||
|
||||
pmesh->scale[1]!=meshscale[1] ||
|
||||
pmesh->scale[2]!=meshscale[2]) {
|
||||
else if (pmesh->scale()[0]!=meshscale[0] ||
|
||||
pmesh->scale()[1]!=meshscale[1] ||
|
||||
pmesh->scale()[2]!=meshscale[2]) {
|
||||
pmesh = model->AddMesh();
|
||||
meshname = meshname + "1";
|
||||
}
|
||||
|
||||
// set fields
|
||||
pmesh->file = meshfile;
|
||||
pmesh->set_file(meshfile);
|
||||
pmesh->name = meshname;
|
||||
pgeom->mesh = meshname;
|
||||
mjuu_copyvec(pmesh->scale, meshscale, 3);
|
||||
pmesh->set_scale(meshscale);
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
+5
-5
@@ -895,7 +895,7 @@ static int Round(double x) {
|
||||
|
||||
// write attribute
|
||||
template<typename T>
|
||||
void mjXUtil::WriteAttr(XMLElement* elem, string name, int n, T* data, const T* def) {
|
||||
void mjXUtil::WriteAttr(XMLElement* elem, string name, int n, const T* data, const T* def) {
|
||||
// make sure all are defined
|
||||
if constexpr (std::is_floating_point_v<T>) {
|
||||
for (int i=0; i<n; i++) {
|
||||
@@ -935,16 +935,16 @@ void mjXUtil::WriteAttr(XMLElement* elem, string name, int n, T* data, const T*
|
||||
|
||||
|
||||
template void mjXUtil::WriteAttr(XMLElement* elem, string name, int n,
|
||||
double* data, const double* def);
|
||||
const double* data, const double* def);
|
||||
|
||||
template void mjXUtil::WriteAttr(XMLElement* elem, string name, int n,
|
||||
float* data, const float* def);
|
||||
const float* data, const float* def);
|
||||
|
||||
template void mjXUtil::WriteAttr(XMLElement* elem, string name, int n,
|
||||
int* data, const int* def);
|
||||
const int* data, const int* def);
|
||||
|
||||
template void mjXUtil::WriteAttr(XMLElement* elem, string name, int n,
|
||||
mjtByte* data, const mjtByte* def);
|
||||
const mjtByte* data, const mjtByte* def);
|
||||
|
||||
|
||||
// write vector<double> attribute, default = zero array
|
||||
|
||||
+1
-1
@@ -179,7 +179,7 @@ class mjXUtil {
|
||||
|
||||
// write attribute- any type
|
||||
template<typename T>
|
||||
static void WriteAttr(tinyxml2::XMLElement* elem, std::string name, int n, T* data,
|
||||
static void WriteAttr(tinyxml2::XMLElement* elem, std::string name, int n, const T* data,
|
||||
const T* def = 0);
|
||||
|
||||
// write vector<double> attribute, with and without default
|
||||
|
||||
Reference in New Issue
Block a user