Skip to content

Commit

Permalink
Merge pull request #181 from cabanier/multi-controller
Browse files Browse the repository at this point in the history
Update input samples so they support more than 2 controllers
  • Loading branch information
cabanier committed Feb 17, 2024
2 parents 9c7e303 + ba92792 commit 6e138f7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions input-profiles.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
// here to handle the animation, but this sample will skip that
// and only display a static mesh for simplicity.

scene.inputRenderer.setControllerMesh(new Gltf2Node({url: assetPath}), inputSource.handedness);
scene.inputRenderer.setControllerMesh(new Gltf2Node({url: assetPath}), inputSource.handedness, inputSource.profiles[0]);
});
}
}
Expand Down Expand Up @@ -213,7 +213,7 @@
if (inputSource.gripSpace) {
let gripPose = frame.getPose(inputSource.gripSpace, refSpace);
if (gripPose) {
scene.inputRenderer.addController(gripPose.transform.matrix, inputSource.handedness);
scene.inputRenderer.addController(gripPose.transform.matrix, inputSource.handedness, inputSource.profiles[0]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion input-tracking.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
if (gripPose) {
// If we have a grip pose use it to render a mesh showing the
// position of the controller.
scene.inputRenderer.addController(gripPose.transform.matrix, inputSource.handedness);
scene.inputRenderer.addController(gripPose.transform.matrix, inputSource.handedness, inputSource.profiles[0]);
}
}

Expand Down
10 changes: 5 additions & 5 deletions js/render/nodes/input-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export class InputRenderer extends Node {
for (let inputSource of event.added) {
if (inputSource.targetRayMode == 'tracked-pointer') {
fetchProfile(inputSource, DEFAULT_PROFILES_PATH).then(({profile, assetPath}) => {
this.setControllerMesh(new Gltf2Node({url: assetPath}), inputSource.handedness);
this.setControllerMesh(new Gltf2Node({url: assetPath}), inputSource.handedness, inputSource.profiles[0]);
});
}
}
Expand All @@ -262,19 +262,19 @@ export class InputRenderer extends Node {
});
}

setControllerMesh(controllerNode, handedness = 'right') {
setControllerMesh(controllerNode, handedness = 'right', profile = '') {
if (!this._controllers) {
this._controllers = {};
}
this._controllers[handedness] = { nodes: [controllerNode], activeCount: 0 };
this._controllers[profile + "_" + handedness] = { nodes: [controllerNode], activeCount: 0 };
controllerNode.visible = false;
// FIXME: Temporary fix to initialize for cloning.
this.addNode(controllerNode);
}

addController(gripMatrix, handedness = 'right') {
addController(gripMatrix, handedness = 'right', profile = '') {
if (!this._controllers || this._blurred) { return; }
let controller = this._controllers[handedness];
let controller = this._controllers[profile + "_" + handedness];

if (!controller) { return; }

Expand Down
2 changes: 1 addition & 1 deletion js/render/scenes/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class Scene extends Node {

// Any time that we have a grip matrix, we'll render a controller.
if (gripPose) {
this.inputRenderer.addController(gripPose.transform.matrix, inputSource.handedness);
this.inputRenderer.addController(gripPose.transform.matrix, inputSource.handedness, inputSource.profiles[0]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/pointer-painter.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
if (inputSource.gripSpace) {
let gripPose = frame.getPose(inputSource.gripSpace, refSpace);
if (gripPose) {
this.scene.inputRenderer.addController(gripPose.transform.matrix, inputSource.handedness);
this.scene.inputRenderer.addController(gripPose.transform.matrix, inputSource.handedness, inputSource.profiles[0]);
}
}
}
Expand Down

0 comments on commit 6e138f7

Please sign in to comment.