Add texture attribute to lights.

PiperOrigin-RevId: 763739805
Change-Id: I333ed2ac68f30f79f688ca01d7b5fd6bf2d836c9
This commit is contained in:
Google DeepMind
2025-05-27 05:03:04 -07:00
committed by Copybara-Service
parent 441ca838a1
commit 568620dd2f
18 changed files with 106 additions and 4 deletions
+1
View File
@@ -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);
+18
View File
@@ -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");
}
}
}
+4
View File
@@ -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; }