From db9913cc3ef84bfadca2d64a946a84f21311dcd9 Mon Sep 17 00:00:00 2001 From: liteng <930372551@qq.com> Date: Tue, 13 Apr 2021 21:32:03 +0800 Subject: [PATCH] add vr controls to a group --- web/src/player/component/WebVR.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/web/src/player/component/WebVR.js b/web/src/player/component/WebVR.js index 8460e4ef..8f30e3b7 100644 --- a/web/src/player/component/WebVR.js +++ b/web/src/player/component/WebVR.js @@ -42,18 +42,23 @@ WebVR.prototype.create = function (scene, camera, renderer) { renderer.xr.enabled = true; this.app.container.appendChild(this.vrButton); + // group + const group = new THREE.Group(); + group.name = 'vr-controls'; + scene.add(group); + // controllers const controller1 = renderer.xr.getController(0); controller1.addEventListener('connected', this.onConnected); controller1.addEventListener('disconnected', this.onDisconnected); controller1.addEventListener('selectstart', this.onSelectStart); controller1.addEventListener('selectend', this.onSelectEnd); - scene.add(controller1); + group.add(controller1); const controller2 = renderer.xr.getController(1); controller2.addEventListener('selectstart', this.onSelectStart); controller2.addEventListener('selectend', this.onSelectEnd); - scene.add(controller2); + group.add(controller2); // Line const geometry = new THREE.BufferGeometry().setFromPoints([ @@ -76,20 +81,20 @@ WebVR.prototype.create = function (scene, camera, renderer) { // Hand 1 const controllerGrip1 = renderer.xr.getControllerGrip(0); controllerGrip1.add(controllerModelFactory.createControllerModel(controllerGrip1)); - scene.add(controllerGrip1); + group.add(controllerGrip1); const hand1 = renderer.xr.getHand(0); hand1.add(handModelFactory.createHandModel(hand1, 'oculus')); // spheres, boxes, oculus - scene.add(hand1); + group.add(hand1); // Hand 2 const controllerGrip2 = renderer.xr.getControllerGrip(1); controllerGrip2.add(controllerModelFactory.createControllerModel(controllerGrip2)); - scene.add(controllerGrip2); + group.add(controllerGrip2); const hand2 = renderer.xr.getHand(1); hand2.add(handModelFactory.createHandModel(hand2, 'oculus')); // spheres, boxes, oculus - scene.add(hand2); + group.add(hand2); resolve(); }); });