Merge branch 'main' into wasm-npm-package
This commit is contained in:
@@ -3934,6 +3934,12 @@ struct MjModel {
|
||||
void set_ntendon(int value) {
|
||||
ptr_->ntendon = static_cast<mjtSize>(value);
|
||||
}
|
||||
int nJten() const {
|
||||
return static_cast<int>(ptr_->nJten);
|
||||
}
|
||||
void set_nJten(int value) {
|
||||
ptr_->nJten = static_cast<mjtSize>(value);
|
||||
}
|
||||
int nwrap() const {
|
||||
return static_cast<int>(ptr_->nwrap);
|
||||
}
|
||||
@@ -4078,12 +4084,6 @@ struct MjModel {
|
||||
void set_nJmom(int value) {
|
||||
ptr_->nJmom = static_cast<mjtSize>(value);
|
||||
}
|
||||
int nJten() const {
|
||||
return static_cast<int>(ptr_->nJten);
|
||||
}
|
||||
void set_nJten(int value) {
|
||||
ptr_->nJten = static_cast<mjtSize>(value);
|
||||
}
|
||||
int ngravcomp() const {
|
||||
return static_cast<int>(ptr_->ngravcomp);
|
||||
}
|
||||
@@ -5125,6 +5125,15 @@ struct MjModel {
|
||||
emscripten::val tendon_treeid() const {
|
||||
return emscripten::val(emscripten::typed_memory_view(ptr_->ntendon * 2, ptr_->tendon_treeid));
|
||||
}
|
||||
emscripten::val ten_J_rownnz() const {
|
||||
return emscripten::val(emscripten::typed_memory_view(ptr_->ntendon, ptr_->ten_J_rownnz));
|
||||
}
|
||||
emscripten::val ten_J_rowadr() const {
|
||||
return emscripten::val(emscripten::typed_memory_view(ptr_->ntendon, ptr_->ten_J_rowadr));
|
||||
}
|
||||
emscripten::val ten_J_colind() const {
|
||||
return emscripten::val(emscripten::typed_memory_view(ptr_->nJten, ptr_->ten_J_colind));
|
||||
}
|
||||
emscripten::val tendon_limited() const {
|
||||
return emscripten::val(emscripten::typed_memory_view(ptr_->ntendon, ptr_->tendon_limited));
|
||||
}
|
||||
@@ -6649,15 +6658,6 @@ struct MjData {
|
||||
emscripten::val ten_wrapnum() const {
|
||||
return emscripten::val(emscripten::typed_memory_view(model->ntendon, ptr_->ten_wrapnum));
|
||||
}
|
||||
emscripten::val ten_J_rownnz() const {
|
||||
return emscripten::val(emscripten::typed_memory_view(model->ntendon, ptr_->ten_J_rownnz));
|
||||
}
|
||||
emscripten::val ten_J_rowadr() const {
|
||||
return emscripten::val(emscripten::typed_memory_view(model->ntendon, ptr_->ten_J_rowadr));
|
||||
}
|
||||
emscripten::val ten_J_colind() const {
|
||||
return emscripten::val(emscripten::typed_memory_view(model->nJten, ptr_->ten_J_colind));
|
||||
}
|
||||
emscripten::val ten_J() const {
|
||||
return emscripten::val(emscripten::typed_memory_view(model->nJten, ptr_->ten_J));
|
||||
}
|
||||
@@ -8329,7 +8329,7 @@ MjSpec::~MjSpec() {
|
||||
mjSpec *MjSpec::get() const { return ptr_; }
|
||||
void MjSpec::set(mjSpec *ptr) { ptr_ = ptr; }
|
||||
|
||||
std::unique_ptr<MjModel> mj_loadXML_wrapper(std::string filename) {
|
||||
std::unique_ptr<MjModel> mj_loadXML_wrapper_1(std::string filename) {
|
||||
char error[1000];
|
||||
mjModel *model = mj_loadXML(filename.c_str(), nullptr, error, sizeof(error));
|
||||
if (!model) {
|
||||
@@ -8338,6 +8338,15 @@ std::unique_ptr<MjModel> mj_loadXML_wrapper(std::string filename) {
|
||||
return std::unique_ptr<MjModel>(new MjModel(model));
|
||||
}
|
||||
|
||||
std::unique_ptr<MjModel> mj_loadXML_wrapper_2(std::string filename, const MjVFS& vfs) {
|
||||
char error[1000];
|
||||
mjModel *model = mj_loadXML(filename.c_str(), vfs.get(), error, sizeof(error));
|
||||
if (!model) {
|
||||
mju_error("Loading error: %s\n", error);
|
||||
}
|
||||
return std::unique_ptr<MjModel>(new MjModel(model));
|
||||
}
|
||||
|
||||
void mj_saveModel_wrapper(const MjModel& m, const StringOrNull& filename, const val& buffer) {
|
||||
UNPACK_NULLABLE_STRING(filename);
|
||||
UNPACK_NULLABLE_VALUE(uint8_t, buffer);
|
||||
@@ -11541,9 +11550,6 @@ EMSCRIPTEN_BINDINGS(mujoco_bindings) {
|
||||
.property("subtree_com", &MjData::subtree_com)
|
||||
.property("subtree_linvel", &MjData::subtree_linvel)
|
||||
.property("ten_J", &MjData::ten_J)
|
||||
.property("ten_J_colind", &MjData::ten_J_colind)
|
||||
.property("ten_J_rowadr", &MjData::ten_J_rowadr)
|
||||
.property("ten_J_rownnz", &MjData::ten_J_rownnz)
|
||||
.property("ten_length", &MjData::ten_length)
|
||||
.property("ten_velocity", &MjData::ten_velocity)
|
||||
.property("ten_wrapadr", &MjData::ten_wrapadr)
|
||||
@@ -11581,8 +11587,9 @@ EMSCRIPTEN_BINDINGS(mujoco_bindings) {
|
||||
.property("useexisting", &MjLROpt::useexisting, &MjLROpt::set_useexisting, reference())
|
||||
.property("uselimit", &MjLROpt::uselimit, &MjLROpt::set_uselimit, reference());
|
||||
emscripten::class_<MjModel>("MjModel")
|
||||
.class_function("mj_loadXML", &mj_loadXML_wrapper, take_ownership())
|
||||
.class_function("mj_loadBinary", &mj_loadModel_wrapper, take_ownership())
|
||||
.class_function("mj_loadXML", emscripten::select_overload<std::unique_ptr<MjModel>(std::string)>(&mj_loadXML_wrapper_1))
|
||||
.class_function("mj_loadXML", emscripten::select_overload<std::unique_ptr<MjModel>(std::string, const MjVFS&)>(&mj_loadXML_wrapper_2))
|
||||
.class_function("mj_loadModel", &mj_loadModel_wrapper)
|
||||
.constructor<const MjModel &>()
|
||||
// Binds the functions on MjModel that return accessors.
|
||||
#define X_ACCESSOR(NAME, Name, OBJTYPE, field_name, nfield) \
|
||||
@@ -12090,6 +12097,9 @@ EMSCRIPTEN_BINDINGS(mujoco_bindings) {
|
||||
.property("skin_vertadr", &MjModel::skin_vertadr)
|
||||
.property("skin_vertnum", &MjModel::skin_vertnum)
|
||||
.property("stat", &MjModel::stat, reference())
|
||||
.property("ten_J_colind", &MjModel::ten_J_colind)
|
||||
.property("ten_J_rowadr", &MjModel::ten_J_rowadr)
|
||||
.property("ten_J_rownnz", &MjModel::ten_J_rownnz)
|
||||
.property("tendon_actfrclimited", &MjModel::tendon_actfrclimited)
|
||||
.property("tendon_actfrcrange", &MjModel::tendon_actfrcrange)
|
||||
.property("tendon_adr", &MjModel::tendon_adr)
|
||||
|
||||
@@ -549,14 +549,19 @@ def _build_struct_bindings(
|
||||
MJDATA_ACCESSORS
|
||||
#undef X_ACCESSOR""".lstrip())
|
||||
elif w == "MjModel":
|
||||
f1 = common.wrapped_function_name(
|
||||
introspect_functions.FUNCTIONS["mj_loadXML"]
|
||||
builder.line(
|
||||
'.class_function("mj_loadXML",'
|
||||
" emscripten::select_overload<std::unique_ptr<MjModel>(std::string)>(&mj_loadXML_wrapper_1))"
|
||||
)
|
||||
builder.line(
|
||||
'.class_function("mj_loadXML",'
|
||||
" emscripten::select_overload<std::unique_ptr<MjModel>(std::string,"
|
||||
" const MjVFS&)>(&mj_loadXML_wrapper_2))"
|
||||
)
|
||||
builder.line(f'.class_function("mj_loadXML", &{f1}, take_ownership())')
|
||||
f2 = common.wrapped_function_name(
|
||||
introspect_functions.FUNCTIONS["mj_loadModel"]
|
||||
)
|
||||
builder.line(f'.class_function("mj_loadBinary", &{f2}, take_ownership())')
|
||||
builder.line(f'.class_function("mj_loadModel", &{f2})')
|
||||
builder.line(".constructor<const MjModel &>()")
|
||||
builder.line("""
|
||||
// Binds the functions on MjModel that return accessors.
|
||||
|
||||
@@ -714,7 +714,7 @@ MjSpec::~MjSpec() {
|
||||
mjSpec *MjSpec::get() const { return ptr_; }
|
||||
void MjSpec::set(mjSpec *ptr) { ptr_ = ptr; }
|
||||
|
||||
std::unique_ptr<MjModel> mj_loadXML_wrapper(std::string filename) {
|
||||
std::unique_ptr<MjModel> mj_loadXML_wrapper_1(std::string filename) {
|
||||
char error[1000];
|
||||
mjModel *model = mj_loadXML(filename.c_str(), nullptr, error, sizeof(error));
|
||||
if (!model) {
|
||||
@@ -723,6 +723,15 @@ std::unique_ptr<MjModel> mj_loadXML_wrapper(std::string filename) {
|
||||
return std::unique_ptr<MjModel>(new MjModel(model));
|
||||
}
|
||||
|
||||
std::unique_ptr<MjModel> mj_loadXML_wrapper_2(std::string filename, const MjVFS& vfs) {
|
||||
char error[1000];
|
||||
mjModel *model = mj_loadXML(filename.c_str(), vfs.get(), error, sizeof(error));
|
||||
if (!model) {
|
||||
mju_error("Loading error: %s\n", error);
|
||||
}
|
||||
return std::unique_ptr<MjModel>(new MjModel(model));
|
||||
}
|
||||
|
||||
void mj_saveModel_wrapper(const MjModel& m, const StringOrNull& filename, const val& buffer) {
|
||||
UNPACK_NULLABLE_STRING(filename);
|
||||
UNPACK_NULLABLE_VALUE(uint8_t, buffer);
|
||||
|
||||
@@ -23,5 +23,9 @@ export default defineConfig({
|
||||
},
|
||||
server: {
|
||||
open: true,
|
||||
headers: {
|
||||
"Cross-Origin-Opener-Policy": "same-origin",
|
||||
"Cross-Origin-Embedder-Policy": "require-corp",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -2512,7 +2512,7 @@ describe('MuJoCo WASM Bindings', () => {
|
||||
|
||||
vfs = new mujoco.MjVFS();
|
||||
vfs.addBuffer(objFilename, new TextEncoder().encode(cube1));
|
||||
binaryModel = mujoco.MjModel.mj_loadBinary(mjbFilename, vfs);
|
||||
binaryModel = mujoco.MjModel.mj_loadModel(mjbFilename, vfs);
|
||||
assertExists(binaryModel);
|
||||
|
||||
expect(mujoco.mj_sizeModel(binaryModel))
|
||||
@@ -2542,7 +2542,7 @@ describe('MuJoCo WASM Bindings', () => {
|
||||
const bufSize = mujoco.mj_sizeModel(model!);
|
||||
|
||||
vfs = new mujoco.MjVFS();
|
||||
binaryModel = mujoco.MjModel.mj_loadBinary(mjbFilename, vfs);
|
||||
binaryModel = mujoco.MjModel.mj_loadModel(mjbFilename, vfs);
|
||||
assertExists(binaryModel);
|
||||
|
||||
expect(mujoco.mj_sizeModel(binaryModel)).toEqual(bufSize);
|
||||
@@ -2558,4 +2558,49 @@ describe('MuJoCo WASM Bindings', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('should load XML with assets from VFS', () => {
|
||||
const xml = `
|
||||
<mujoco>
|
||||
<asset>
|
||||
<mesh file="cube.obj"/>
|
||||
</asset>
|
||||
<worldbody>
|
||||
<geom type="mesh" mesh="cube"/>
|
||||
</worldbody>
|
||||
</mujoco>`;
|
||||
|
||||
const cube1 = `
|
||||
v -1 -1 1
|
||||
v 1 -1 1
|
||||
v -1 1 1
|
||||
v 1 1 1
|
||||
v -1 1 -1
|
||||
v 1 1 -1
|
||||
v -1 -1 -1
|
||||
v 1 -1 -1`;
|
||||
|
||||
const xmlFilename = '/tmp/with_vfs.xml';
|
||||
writeXMLFile(xmlFilename, xml);
|
||||
|
||||
let model: MjModel|null = null;
|
||||
let vfs: MjVFS|null = null;
|
||||
try {
|
||||
vfs = new mujoco.MjVFS();
|
||||
vfs.addBuffer('cube.obj', new TextEncoder().encode(cube1));
|
||||
assertExists(vfs);
|
||||
|
||||
model = mujoco.MjModel.mj_loadXML(xmlFilename, vfs);
|
||||
assertExists(model);
|
||||
expect(model.nmesh).toBe(1);
|
||||
|
||||
const meshId =
|
||||
mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_MESH.value, 'cube');
|
||||
expect(meshId).toBeGreaterThanOrEqual(0);
|
||||
} finally {
|
||||
model?.delete();
|
||||
vfs?.delete();
|
||||
unlinkXMLFile(xmlFilename);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -40,6 +40,10 @@ describe('Enums', () => {
|
||||
expect(mujoco.mjtGeom).toBeDefined();
|
||||
});
|
||||
|
||||
it('mjtProjection should exist', () => {
|
||||
expect(mujoco.mjtProjection).toBeDefined();
|
||||
});
|
||||
|
||||
it('mjtCamLight should exist', () => {
|
||||
expect(mujoco.mjtCamLight).toBeDefined();
|
||||
});
|
||||
@@ -120,6 +124,14 @@ describe('Enums', () => {
|
||||
expect(mujoco.mjtConDataField).toBeDefined();
|
||||
});
|
||||
|
||||
it('mjtRayDataField should exist', () => {
|
||||
expect(mujoco.mjtRayDataField).toBeDefined();
|
||||
});
|
||||
|
||||
it('mjtCamOutBit should exist', () => {
|
||||
expect(mujoco.mjtCamOutBit).toBeDefined();
|
||||
});
|
||||
|
||||
it('mjtSameFrame should exist', () => {
|
||||
expect(mujoco.mjtSameFrame).toBeDefined();
|
||||
});
|
||||
|
||||
@@ -23,5 +23,9 @@ export default defineConfig({
|
||||
},
|
||||
server: {
|
||||
open: true,
|
||||
headers: {
|
||||
"Cross-Origin-Opener-Policy": "same-origin",
|
||||
"Cross-Origin-Embedder-Policy": "require-corp",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user