Add texture attribute to lights.
PiperOrigin-RevId: 763739805 Change-Id: I333ed2ac68f30f79f688ca01d7b5fd6bf2d836c9
This commit is contained in:
committed by
Copybara-Service
parent
441ca838a1
commit
568620dd2f
@@ -2143,8 +2143,12 @@ void mjv_makeLights(const mjModel* m, const mjData* d, mjvScene* scn) {
|
||||
// set default properties
|
||||
memset(thislight, 0, sizeof(mjvLight));
|
||||
thislight->headlight = 1;
|
||||
thislight->texid = -1;
|
||||
thislight->type = mjLIGHT_DIRECTIONAL;
|
||||
thislight->castshadow = 0;
|
||||
thislight->bulbradius = 0.02;
|
||||
thislight->intensity = 1000;
|
||||
thislight->range = 10;
|
||||
|
||||
// compute head position and gaze direction in model space
|
||||
mjtNum hpos[3], hfwd[3];
|
||||
@@ -2170,6 +2174,7 @@ void mjv_makeLights(const mjModel* m, const mjData* d, mjvScene* scn) {
|
||||
// copy properties
|
||||
memset(thislight, 0, sizeof(mjvLight));
|
||||
thislight->type = m->light_type[i];
|
||||
thislight->texid = m->light_texid[i];
|
||||
thislight->castshadow = m->light_castshadow[i];
|
||||
thislight->bulbradius = m->light_bulbradius[i];
|
||||
thislight->intensity = m->light_intensity[i];
|
||||
|
||||
@@ -2670,6 +2670,7 @@ void mjCModel::CopyTree(mjModel* m) {
|
||||
m->light_mode[lid] = (int)pl->mode;
|
||||
m->light_targetbodyid[lid] = pl->targetbodyid;
|
||||
m->light_type[lid] = pl->type;
|
||||
m->light_texid[lid] = pl->texid;
|
||||
m->light_castshadow[lid] = (mjtByte)pl->castshadow;
|
||||
m->light_active[lid] = (mjtByte)pl->active;
|
||||
mjuu_copyvec(m->light_pos+3*lid, pl->pos, 3);
|
||||
|
||||
@@ -3553,7 +3553,10 @@ mjCLight::mjCLight(mjCModel* _model, mjCDef* _def) {
|
||||
// clear private variables
|
||||
body = 0;
|
||||
targetbodyid = -1;
|
||||
texid = -1;
|
||||
spec_targetbody_.clear();
|
||||
spec_texture_.clear();
|
||||
|
||||
|
||||
// reset to default if given
|
||||
if (_def) {
|
||||
@@ -3593,6 +3596,7 @@ void mjCLight::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.targetbody = &spec_targetbody_;
|
||||
spec.texture = &spec_texture_;
|
||||
spec.info = &info;
|
||||
targetbody = nullptr;
|
||||
}
|
||||
@@ -3604,6 +3608,9 @@ void mjCLight::NameSpace(const mjCModel* m) {
|
||||
if (!spec_targetbody_.empty()) {
|
||||
spec_targetbody_ = m->prefix + spec_targetbody_ + m->suffix;
|
||||
}
|
||||
if (!spec_texture_.empty()) {
|
||||
spec_texture_ = m->prefix + spec_texture_ + m->suffix;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3611,6 +3618,7 @@ void mjCLight::NameSpace(const mjCModel* m) {
|
||||
void mjCLight::CopyFromSpec() {
|
||||
*static_cast<mjsLight*>(this) = spec;
|
||||
targetbody_ = spec_targetbody_;
|
||||
texture_ = spec_texture_;
|
||||
}
|
||||
|
||||
|
||||
@@ -3643,6 +3651,16 @@ void mjCLight::Compile(void) {
|
||||
throw mjCError(this, "unknown target body in light");
|
||||
}
|
||||
}
|
||||
|
||||
// get texture
|
||||
if (!texture_.empty()) {
|
||||
mjCTexture* tex = (mjCTexture*)model->FindObject(mjOBJ_TEXTURE, texture_);
|
||||
if (tex) {
|
||||
texid = tex->id;
|
||||
} else {
|
||||
throw mjCError(this, "unknown target body in light");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -793,6 +793,9 @@ class mjCLight_ : public mjCBase {
|
||||
protected:
|
||||
mjCBody* body; // light's body
|
||||
int targetbodyid; // id of target body; -1: none
|
||||
int texid; // id of texture; -1: none
|
||||
std::string texture_;
|
||||
std::string spec_texture_;
|
||||
std::string targetbody_;
|
||||
std::string spec_targetbody_;
|
||||
};
|
||||
@@ -814,6 +817,7 @@ class mjCLight : public mjCLight_, private mjsLight {
|
||||
|
||||
// used by mjXWriter and mjCModel
|
||||
const std::string& get_targetbody() const { return targetbody_; }
|
||||
const std::string& get_texture() const { return texture_; }
|
||||
|
||||
void SetParent(mjCBody* _body) { body = _body; }
|
||||
mjCBody* GetParent() const { return body; }
|
||||
|
||||
@@ -281,9 +281,9 @@ const char* MJCF[nMJCF][mjXATTRNUM] = {
|
||||
{"camera", "*", "20", "name", "class", "orthographic", "fovy", "ipd", "resolution", "pos",
|
||||
"quat", "axisangle", "xyaxes", "zaxis", "euler", "mode", "target",
|
||||
"focal", "focalpixel", "principal", "principalpixel", "sensorsize", "user"},
|
||||
{"light", "*", "19", "name", "class", "directional", "type", "castshadow", "active",
|
||||
{"light", "*", "20", "name", "class", "directional", "type", "castshadow", "active",
|
||||
"pos", "dir", "bulbradius", "intensity", "range", "attenuation", "cutoff",
|
||||
"exponent", "ambient", "diffuse", "specular", "mode", "target"},
|
||||
"exponent", "ambient", "diffuse", "specular", "mode", "target", "texture"},
|
||||
{"plugin", "*", "2", "plugin", "instance"},
|
||||
{"<"},
|
||||
{"config", "*", "2", "key", "value"},
|
||||
@@ -1864,12 +1864,15 @@ void mjXReader::OneCamera(XMLElement* elem, mjsCamera* camera) {
|
||||
void mjXReader::OneLight(XMLElement* elem, mjsLight* light) {
|
||||
int n;
|
||||
bool has_directional = false;
|
||||
string text, name, targetbody;
|
||||
string text, name, texture, targetbody;
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(light->name, name.c_str());
|
||||
}
|
||||
if (ReadAttrTxt(elem, "texture", texture)) {
|
||||
mjs_setString(light->texture, texture.c_str());
|
||||
}
|
||||
if (ReadAttrTxt(elem, "target", targetbody)) {
|
||||
mjs_setString(light->targetbody, targetbody.c_str());
|
||||
}
|
||||
|
||||
@@ -608,6 +608,7 @@ void mjXWriter::OneLight(XMLElement* elem, const mjCLight* light, mjCDef* def,
|
||||
WriteAttr(elem, "intensity", 1, &light->intensity, &def->Light().intensity);
|
||||
WriteAttr(elem, "range", 1, &light->range, &def->Light().range);
|
||||
WriteAttrKey(elem, "type", lighttype_map, lighttype_sz, light->type, def->Light().type);
|
||||
WriteAttrTxt(elem, "texture", light->get_texture());
|
||||
WriteAttrKey(elem, "castshadow", bool_map, 2, light->castshadow, def->Light().castshadow);
|
||||
WriteAttrKey(elem, "active", bool_map, 2, light->active, def->Light().active);
|
||||
WriteAttr(elem, "attenuation", 3, light->attenuation, def->Light().attenuation);
|
||||
|
||||
Reference in New Issue
Block a user