add content_type to model in the XML schema.
PiperOrigin-RevId: 670961443 Change-Id: I98cd6bb61b50029cdd4f5b31e23d268989d136da
This commit is contained in:
committed by
Copybara-Service
parent
9a27fc14c2
commit
0e8c0b80eb
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user