我想弄清楚如何使用three.js 和webXR 为我的oculus quest 和其他设备绘制控件。该代码有效,并允许我移动控制器,将一个圆柱体映射到每个控件,并允许我使用触发器来更改圆柱体的颜色。这很棒,但我找不到任何关于如何使用操纵杆、手柄和其他按钮的轴控制的文档。我的一部分想相信它就像知道要调用哪个事件一样简单,因为我不知道还有哪些其他事件可用。
这是我基于此的教程的链接。https://github.com/as-ideas/webvr-with-threejs
请注意,此代码按预期工作,但我不知道如何进一步执行并执行更多操作。
function createController(controllerID, videoinput) {
//RENDER CONTROLLER AS YELLOW TUBE
const controller = renderer.vr.getController(controllerID);
const cylinderGeometry = new CylinderGeometry(0.025, 0.025, 1, 32);
const cylinderMaterial = new MeshPhongMaterial({ color: 0xffff00 });
const cylinder = new Mesh(cylinderGeometry, cylinderMaterial);
cylinder.geometry.translate(0, 0.5, 0);
cylinder.rotateX(-0.25 * Math.PI);
controller.add(cylinder);
cameraFixture.add(controller);
//TRIGGER
controller.addEventListener('selectstart', () => {
if (controllerID === 0) {
cylinderMaterial.color.set('pink')
} else {
cylinderMaterial.color.set('orange');
videoinput.play()
}
});
controller.addEventListener('selectend', () => {
cylinderMaterial.color.set(0xffff00);
videoinput.pause();
console.log('I pressed play');
});
}
Run Code Online (Sandbox Code Playgroud)