Add custom Emscripten binding for mj_saveModel.
Also adds support to unpack nullable string args PiperOrigin-RevId: 859702186 Change-Id: Ia9e10f447ecf17b1dd74dd64d988790107a438a6
This commit is contained in:
committed by
Copybara-Service
parent
5ae6b5fe31
commit
61f13cd8f1
@@ -17,7 +17,7 @@ import 'jasmine';
|
||||
import {MainModule, MjContact, MjContactVec, MjData, MjLROpt, MjModel,
|
||||
MjOption, MjsGeom, MjSolverStat, MjSpec, MjStatistic, MjTimerStat, MjvCamera,
|
||||
MjvFigure, MjvGeom, MjvGLCamera, MjvLight, MjvOption, MjvPerturb, MjvScene,
|
||||
MjWarningStat, MjVFS} from '../dist/mujoco_wasm.js';
|
||||
MjWarningStat, MjVFS, Uint8Buffer} from '../dist/mujoco_wasm.js';
|
||||
|
||||
import loadMujoco from '../dist/mujoco_wasm.js'
|
||||
|
||||
@@ -2140,4 +2140,40 @@ describe('MuJoCo WASM Bindings', () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should save model to buffer', () => {
|
||||
assertExists(model);
|
||||
const modelSize = mujoco.mj_sizeModel(model);
|
||||
const buffer = new mujoco.Uint8Buffer(Number(modelSize));
|
||||
try {
|
||||
mujoco.mj_saveModel(model, null, buffer);
|
||||
// Test the first 3 byte values of the buffer.
|
||||
expect(buffer.GetView()[0]).toBe(49);
|
||||
expect(buffer.GetView()[1]).toBe(212);
|
||||
expect(buffer.GetView()[2]).toBe(0);
|
||||
} finally {
|
||||
buffer.delete();
|
||||
}
|
||||
});
|
||||
|
||||
it('should save model to file', () => {
|
||||
assertExists(model);
|
||||
const filename = '/tmp/test.mjb';
|
||||
const modelSize = mujoco.mj_sizeModel(model);
|
||||
const buffer = new mujoco.Uint8Buffer(Number(modelSize));
|
||||
try {
|
||||
mujoco.mj_saveModel(model, filename, null);
|
||||
const fileContent =
|
||||
(mujoco as any).FS.readFile(filename, {encoding: 'binary'});
|
||||
|
||||
mujoco.mj_saveModel(model, null, buffer);
|
||||
const bufferContent = buffer.GetView();
|
||||
|
||||
expect(fileContent.length).toBe(bufferContent.length);
|
||||
expect(fileContent).toEqual(bufferContent);
|
||||
} finally {
|
||||
buffer.delete();
|
||||
unlinkXMLFile(filename);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user