add content_type to model in the XML schema.

PiperOrigin-RevId: 670961443
Change-Id: I98cd6bb61b50029cdd4f5b31e23d268989d136da
This commit is contained in:
Alessio Quaglino
2024-09-04 07:24:48 -07:00
committed by Copybara-Service
parent 9a27fc14c2
commit 0e8c0b80eb
5 changed files with 31 additions and 7 deletions
+5
View File
@@ -1893,6 +1893,11 @@ This element specifies other MJCF models which may be used for :ref:`attachment<
:at:`file`: :at-val:`string, required`
The file from which the sub-model will be loaded. Note that the sub-model must be a valid MJCF model.
.. _asset-model-content_type:
:at:`content_type` :at-val:`string, optional`
The file type to be loaded into a model. Currently only text/xml is supported.
.. _body:
+1 -1
View File
@@ -244,7 +244,7 @@
| :ref:`model | \* | :class: mjcf-attributes |
| <asset-model>` | | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`name<asset-model-name>` | :ref:`file<asset-model-file>` | | | |
| | | | :ref:`name<asset-model-name>` | :ref:`file<asset-model-file>` | :ref:`content_type<asset-model-content_type>` | | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
+------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| mujoco |br| |L| | | .. table:: |
+10 -2
View File
@@ -1382,8 +1382,16 @@ void mjr_uploadTexture(const mjModel* m, const mjrContext* con, int texid) {
glTexGenfv(GL_T, GL_OBJECT_PLANE, plane);
// assign data
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m->tex_width[texid], m->tex_height[texid], 0,
GL_RGB, GL_UNSIGNED_BYTE, m->tex_data + m->tex_adr[texid]);
int type = 0;
if (m->tex_nchannel[texid] == 3) {
type = GL_RGB;
} else if (m->tex_nchannel[texid] == 4) {
type = GL_RGBA;
} else {
mju_error("Number of channels not supported: %d", m->tex_nchannel[texid]);
}
glTexImage2D(GL_TEXTURE_2D, 0, type, m->tex_width[texid], m->tex_height[texid], 0,
type, GL_UNSIGNED_BYTE, m->tex_data + m->tex_adr[texid]);
// generate mipmaps
glGenerateMipmap(GL_TEXTURE_2D);
+1 -1
View File
@@ -1547,7 +1547,7 @@ void mjCModel::SetSizes() {
for (int i=0; i<nhfield; i++) nhfielddata += hfields_[i]->nrow * hfields_[i]->ncol;
// ntexdata
for (int i=0; i<ntex; i++) ntexdata += 3 * textures_[i]->width * textures_[i]->height;
for (int i=0; i<ntex; i++) ntexdata += textures_[i]->nchannel * textures_[i]->width * textures_[i]->height;
// nwrap
for (int i=0; i<ntendon; i++) nwrap += (int)tendons_[i]->path.size();
+14 -3
View File
@@ -258,7 +258,7 @@ const char* MJCF[nMJCF][mjXATTRNUM] = {
{"rgba", "?", "1", "texture"},
{"orm", "?", "1", "texture"},
{">"},
{"model", "*", "2", "name", "file"},
{"model", "*", "3", "name", "file", "content_type"},
{">"},
{"body", "R", "11", "name", "childclass", "pos", "quat", "mocap",
@@ -3306,11 +3306,22 @@ void mjXReader::Asset(XMLElement* section, const mjVFS* vfs) {
// model sub-element
else if (name=="model") {
auto filename = modelfiledir_ + ReadAttrFile(elem, "file", vfs).value();
string content_type;
if (!ReadAttrTxt(elem, "content_type", content_type)) {
content_type = "text/xml";
}
// parse the child
mjSpec* child = nullptr;
std::array<char, 1024> error;
mjSpec* child = mj_parseXML(filename.c_str(), vfs, error.data(), error.size());
auto filename = modelfiledir_ + ReadAttrFile(elem, "file", vfs).value();
if (content_type == "text/xml") {
child = mj_parseXML(filename.c_str(), vfs, error.data(), error.size());
} else {
throw mjXError(elem, "unsupported content_type: %s", content_type.c_str());
}
if (!child) {
throw mjXError(elem, "could not parse model file with error: %s", error.data());
}