Skip to content

Commit 26ea20a

Browse files
Google DeepMindcopybara-github
authored andcommitted
No public description
PiperOrigin-RevId: 809074980 Change-Id: Ib3e3522addceddba6a057cfef80fcbd30a420b3d
1 parent 77e025e commit 26ea20a

File tree

16 files changed

+79
-98
lines changed

16 files changed

+79
-98
lines changed

doc/includes/references.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,8 +1845,6 @@ typedef struct mjsCompiler_ { // compiler options
18451845
mjtByte saveinertial; // save explicit inertial clause for all bodies to XML
18461846
int alignfree; // align free joints with inertial frame
18471847
mjLROpt LRopt; // options for lengthrange computation
1848-
mjString* meshdir; // mesh and hfield directory
1849-
mjString* texturedir; // texture directory
18501848
} mjsCompiler;
18511849
typedef struct mjSpec_ { // model specification
18521850
mjsElement* element; // element type
@@ -1855,6 +1853,8 @@ typedef struct mjSpec_ { // model specification
18551853
// compiler data
18561854
mjsCompiler compiler; // compiler options
18571855
mjtByte strippath; // automatically strip paths from mesh files
1856+
mjString* meshdir; // mesh and hfield directory
1857+
mjString* texturedir; // texture directory
18581858

18591859
// engine data
18601860
mjOption option; // physics options

include/mujoco/mjspec.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ typedef struct mjsCompiler_ { // compiler options
151151
mjtByte saveinertial; // save explicit inertial clause for all bodies to XML
152152
int alignfree; // align free joints with inertial frame
153153
mjLROpt LRopt; // options for lengthrange computation
154-
mjString* meshdir; // mesh and hfield directory
155-
mjString* texturedir; // texture directory
156154
} mjsCompiler;
157155

158156

@@ -163,6 +161,8 @@ typedef struct mjSpec_ { // model specification
163161
// compiler data
164162
mjsCompiler compiler; // compiler options
165163
mjtByte strippath; // automatically strip paths from mesh files
164+
mjString* meshdir; // mesh and hfield directory
165+
mjString* texturedir; // texture directory
166166

167167
// engine data
168168
mjOption option; // physics options

python/mujoco/introspect/structs.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7928,20 +7928,6 @@
79287928
type=ValueType(name='mjLROpt'),
79297929
doc='options for lengthrange computation',
79307930
),
7931-
StructFieldDecl(
7932-
name='meshdir',
7933-
type=PointerType(
7934-
inner_type=ValueType(name='mjString'),
7935-
),
7936-
doc='mesh and hfield directory',
7937-
),
7938-
StructFieldDecl(
7939-
name='texturedir',
7940-
type=PointerType(
7941-
inner_type=ValueType(name='mjString'),
7942-
),
7943-
doc='texture directory',
7944-
),
79457931
),
79467932
)),
79477933
('mjSpec',
@@ -7973,6 +7959,20 @@
79737959
type=ValueType(name='mjtByte'),
79747960
doc='automatically strip paths from mesh files',
79757961
),
7962+
StructFieldDecl(
7963+
name='meshdir',
7964+
type=PointerType(
7965+
inner_type=ValueType(name='mjString'),
7966+
),
7967+
doc='mesh and hfield directory',
7968+
),
7969+
StructFieldDecl(
7970+
name='texturedir',
7971+
type=PointerType(
7972+
inner_type=ValueType(name='mjString'),
7973+
),
7974+
doc='texture directory',
7975+
),
79767976
StructFieldDecl(
79777977
name='option',
79787978
type=ValueType(name='mjOption'),

python/mujoco/specs.cc

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -593,22 +593,6 @@ PYBIND11_MODULE(_specs, m) {
593593
},
594594
py::arg("degree"), py::arg("sequence") = py::none(),
595595
py::arg("orientation"), py::return_value_policy::copy);
596-
mjSpec.def_property(
597-
"meshdir",
598-
[](MjSpec& self) -> std::string_view {
599-
return *self.ptr->compiler.meshdir;
600-
},
601-
[](MjSpec& self, std::string_view meshdir) {
602-
*(self.ptr->compiler.meshdir) = meshdir;
603-
});
604-
mjSpec.def_property(
605-
"texturedir",
606-
[](MjSpec& self) -> std::string_view {
607-
return *self.ptr->compiler.texturedir;
608-
},
609-
[](MjSpec& self, std::string_view texturedir) {
610-
*(self.ptr->compiler.texturedir) = texturedir;
611-
});
612596

613597
// ============================= MJSBODY =====================================
614598
mjsBody.def(

src/user/user_api.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ int mjs_isWarning(mjSpec* s) {
297297
void mj_deleteSpec(mjSpec* s) {
298298
if (s) {
299299
mjCModel* model = static_cast<mjCModel*>(s->element);
300-
model->Release();
300+
delete model;
301301
}
302302
}
303303

src/user/user_flexcomp.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ bool mjCFlexcomp::Make(mjsBody* body, char* error, int error_sz) {
170170
break;
171171

172172
case mjFCOMPTYPE_MESH:
173-
res = MakeMesh(model, compiler, error, error_sz);
173+
res = MakeMesh(model, error, error_sz);
174174
break;
175175

176176
case mjFCOMPTYPE_GMSH:
177-
res = MakeGMSH(model, compiler, error, error_sz);
177+
res = MakeGMSH(model, error, error_sz);
178178
break;
179179

180180
case mjFCOMPTYPE_DIRECT:
@@ -1075,7 +1075,7 @@ template <typename T> static T* VecToArray(std::vector<T>& vector, bool clear =
10751075

10761076

10771077
// make mesh
1078-
bool mjCFlexcomp::MakeMesh(mjCModel* model, mjsCompiler* compiler, char* error, int error_sz) {
1078+
bool mjCFlexcomp::MakeMesh(mjCModel* model, char* error, int error_sz) {
10791079
// strip path
10801080
if (!file.empty() && model->spec.strippath) {
10811081
file = mjuu_strippath(file);
@@ -1092,7 +1092,7 @@ bool mjCFlexcomp::MakeMesh(mjCModel* model, mjsCompiler* compiler, char* error,
10921092
}
10931093

10941094
// load resource
1095-
std::string filename = mjuu_combinePaths(mjs_getString(compiler->meshdir), file);
1095+
std::string filename = mjuu_combinePaths(mjs_getString(model->spec.meshdir), file);
10961096
mjResource* resource = nullptr;
10971097

10981098

@@ -1194,7 +1194,7 @@ static int findstring(const char* buffer, int buffer_sz, const char* str) {
11941194

11951195

11961196
// load points and elements from GMSH file
1197-
bool mjCFlexcomp::MakeGMSH(mjCModel* model, mjsCompiler* compiler, char* error, int error_sz) {
1197+
bool mjCFlexcomp::MakeGMSH(mjCModel* model, char* error, int error_sz) {
11981198
// strip path
11991199
if (!file.empty() && model->spec.strippath) {
12001200
file = mjuu_strippath(file);
@@ -1208,7 +1208,7 @@ bool mjCFlexcomp::MakeGMSH(mjCModel* model, mjsCompiler* compiler, char* error,
12081208
// open resource
12091209
mjResource* resource = nullptr;
12101210
try {
1211-
std::string filename = mjuu_combinePaths(mjs_getString(compiler->meshdir), file);
1211+
std::string filename = mjuu_combinePaths(mjs_getString(model->spec.meshdir), file);
12121212
resource = mjCBase::LoadResource(mjs_getString(model->spec.modelfiledir),
12131213
filename, 0);
12141214
} catch (mjCError err) {

src/user/user_flexcomp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ class mjCFlexcomp {
5757
bool MakeGrid(char* error, int error_sz);
5858
bool MakeBox(char* error, int error_sz, int dim, bool open = true);
5959
bool MakeSquare(char* error, int error_sz);
60-
bool MakeMesh(mjCModel* model, mjsCompiler* compiler, char* error, int error_sz);
61-
bool MakeGMSH(mjCModel* model, mjsCompiler* compiler, char* error, int error_sz);
60+
bool MakeMesh(mjCModel* model, char* error, int error_sz);
61+
bool MakeGMSH(mjCModel* model, char* error, int error_sz);
6262
void LoadGMSH(mjCModel* model, mjResource* resource);
6363
void LoadGMSH41(char* buffer, int binary, int nodeend, int nodebegin,
6464
int elemend, int elembegin);

src/user/user_mesh.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ void mjCMesh::NameSpace(const mjCModel* m) {
303303
if (modelfiledir_.empty()) {
304304
modelfiledir_ = FilePath(m->spec_modelfiledir_);
305305
}
306+
if (meshdir_.empty()) {
307+
meshdir_ = FilePath(m->spec_meshdir_);
308+
}
306309
if (!plugin_instance_name.empty()) {
307310
plugin_instance_name = m->prefix + plugin_instance_name + m->suffix;
308311
}
@@ -702,12 +705,12 @@ void mjCMesh::TryCompile(const mjVFS* vfs) {
702705
}
703706

704707
// copy paths from model if not already defined
705-
mujoco::user::FilePath meshdir_;
706-
meshdir_ = FilePath(mjs_getString(compiler->meshdir));
707-
708708
if (modelfiledir_.empty()) {
709709
modelfiledir_ = FilePath(model->modelfiledir_);
710710
}
711+
if (meshdir_.empty()) {
712+
meshdir_ = FilePath(model->meshdir_);
713+
}
711714

712715
// remove path from file if necessary
713716
if (model->strippath) {
@@ -3128,6 +3131,9 @@ void mjCSkin::NameSpace(const mjCModel* m) {
31283131
if (modelfiledir_.empty()) {
31293132
modelfiledir_ = FilePath(m->spec_modelfiledir_);
31303133
}
3134+
if (meshdir_.empty()) {
3135+
meshdir_ = FilePath(m->spec_meshdir_);
3136+
}
31313137
}
31323138

31333139

@@ -3218,8 +3224,9 @@ void mjCSkin::Compile(const mjVFS* vfs) {
32183224
if (modelfiledir_.empty()) {
32193225
modelfiledir_ = FilePath(model->modelfiledir_);
32203226
}
3221-
mujoco::user::FilePath meshdir_;
3222-
meshdir_ = FilePath(mjs_getString(compiler->meshdir));
3227+
if (meshdir_.empty()) {
3228+
meshdir_ = FilePath(model->meshdir_);
3229+
}
32233230

32243231
FilePath filename = meshdir_ + FilePath(file_);
32253232
mjResource* resource = LoadResource(modelfiledir_.Str(), filename.Str(), vfs);

src/user/user_model.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ mjCModel::mjCModel() {
140140
elemtype = mjOBJ_MODEL;
141141
spec_comment_.clear();
142142
spec_modelfiledir_.clear();
143-
meshdir_.clear();
144-
texturedir_.clear();
143+
spec_meshdir_.clear();
144+
spec_texturedir_.clear();
145145
spec_modelname_ = "MuJoCo Model";
146146

147147
//------------------------ auto-computed statistics
@@ -201,12 +201,10 @@ mjCModel& mjCModel::operator=(const mjCModel& other) {
201201
this->spec = other.spec;
202202
*static_cast<mjCModel_*>(this) = static_cast<const mjCModel_&>(other);
203203
*static_cast<mjSpec*>(this) = static_cast<const mjSpec&>(other);
204-
PointToLocal();
205204

206205
// copy attached specs first so that we can resolve references to them
207-
for (auto* s : other.specs_) {
208-
specs_.push_back(s);
209-
static_cast<mjCModel*>(s->element)->AddRef();
206+
for (const auto* s : other.specs_) {
207+
specs_.push_back(mj_copySpec(s));
210208
compiler2spec_[&s->compiler] = specs_.back();
211209
}
212210

@@ -871,11 +869,13 @@ void mjCModel::PointToLocal() {
871869
spec.comment = &spec_comment_;
872870
spec.modelfiledir = &spec_modelfiledir_;
873871
spec.modelname = &spec_modelname_;
874-
spec.compiler.meshdir = &meshdir_;
875-
spec.compiler.texturedir = &texturedir_;
872+
spec.meshdir = &spec_meshdir_;
873+
spec.texturedir = &spec_texturedir_;
876874
comment = nullptr;
877875
modelfiledir = nullptr;
878876
modelname = nullptr;
877+
meshdir = nullptr;
878+
texturedir = nullptr;
879879
}
880880

881881

@@ -885,6 +885,8 @@ void mjCModel::CopyFromSpec() {
885885
comment_ = spec_comment_;
886886
modelfiledir_ = spec_modelfiledir_;
887887
modelname_ = spec_modelname_;
888+
meshdir_ = spec_meshdir_;
889+
texturedir_ = spec_texturedir_;
888890
}
889891

890892

src/user/user_model.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ class mjCModel_ : public mjsElement {
148148
std::string spec_comment_;
149149
std::string spec_modelfiledir_;
150150
std::string spec_modelname_;
151+
std::string spec_meshdir_;
152+
std::string spec_texturedir_;
151153
};
152154

153155
// mjCModel contains everything needed to generate the low-level model.
@@ -328,18 +330,7 @@ class mjCModel : public mjCModel_, private mjSpec {
328330
// check for repeated names in list
329331
void CheckRepeat(mjtObj type);
330332

331-
// increment and decrement reference count
332-
void AddRef() { ++refcount; }
333-
int GetRef() const { return refcount; }
334-
void Release() {
335-
if (--refcount == 0) {
336-
delete this;
337-
}
338-
}
339-
340333
private:
341-
int refcount = 1;
342-
343334
// settings for each defaults class
344335
std::vector<mjCDef*> defaults_;
345336

0 commit comments

Comments
 (0)