Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

body names should now be correct in humanoid example #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion examples/mujocoUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,23 @@ export async function loadSceneFromURL(mujoco, filename, parent) {
let textDecoder = new TextDecoder("utf-8");
let fullString = textDecoder.decode(model.names);
let names = fullString.split(textDecoder.decode(new ArrayBuffer(1)));

// model.names is an array of utf values, with 0 as a separator.
// first we split the array at each 0, then we decode each subarray into a string,
// and store the index of the first character as a key
// (since model.name_bodyadr contains the index of the first character of the body name).
let current = [];
let current_firstchar_index = 0;
let name_index = {};
for (let i = 0; i < model.names.length; i++) {
if (model.names[i] == 0) {
name_index[current_firstchar_index] = textDecoder.decode(new Uint8Array(current));
current = [];
current_firstchar_index = i + 1;
} else {
current.push(model.names[i]);
}
}

// Create the root object.
let mujocoRoot = new THREE.Group();
Expand Down Expand Up @@ -321,7 +338,7 @@ export async function loadSceneFromURL(mujoco, filename, parent) {
// Create the body if it doesn't exist.
if (!(b in bodies)) {
bodies[b] = new THREE.Group();
bodies[b].name = names[model.name_bodyadr[b]];
bodies[b].name = name_index[model.name_bodyadr[b]];
bodies[b].bodyID = b;
bodies[b].has_custom_mesh = false;
}
Expand Down