three.js/web vr样板文件/polyfill-HMD到受控对象:轴重新映射不会重新映射旋转顺序/规则

three.js/web vr样板文件/polyfill-HMD到受控对象:轴重新映射不会重新映射旋转顺序/规则,three.js,polyfills,webvr,Three.js,Polyfills,Webvr,我正在使用您的webvr样板,并尝试将其映射到人脸网格 我的做法是: 1) 将相机连接到眼骨上 主js脚本: //add camera to eye mesh.skeleton.bones[ 22 ].add(camera); //resets camera rotation camera.rotation.set(0,0,0); //looks at mesh up direction to face front camera.lookAt( mesh.up ); //moves cam

我正在使用您的webvr样板,并尝试将其映射到人脸网格

我的做法是:

1) 将相机连接到眼骨上

主js脚本

//add camera to eye
mesh.skeleton.bones[ 22 ].add(camera);

//resets camera rotation
camera.rotation.set(0,0,0);

//looks at mesh up direction to face front
camera.lookAt( mesh.up );

//moves camera to middle of eyes 
camera.position.set(10,10,0);
if ( state.orientation !== null ) {

     object.quaternion.copy( state.orientation );

 }

if ( state.position !== null ) {

     object.position.copy( state.position ).multiplyScalar( scope.scale );

 }
 /* INSIDE UPDATE CYCLE */

// mesh.rotation.y+=0.1;
controls.update();

//resets bone position to default
mesh.skeleton.bones[ neckVRControlBone ].position.set(neckInitPosition.x,neckInitPosition.y,neckInitPosition.z) ;


//ROTATION SWAP
mesh.skeleton.bones[ neckVRControlBone ].rotation.x = pivot.rotation.y;

mesh.skeleton.bones[ neckVRControlBone ].rotation.y = - pivot.rotation.z;

mesh.skeleton.bones[ neckVRControlBone ].rotation.z = - tempRotation;
2) 更改webvr-manager.js以更新颈部骨骼(在初始化时作为参数传递)的位置和旋转,并在index.php中交换轴以使HMD轴与骨骼轴匹配:

webvr manager.js

//add camera to eye
mesh.skeleton.bones[ 22 ].add(camera);

//resets camera rotation
camera.rotation.set(0,0,0);

//looks at mesh up direction to face front
camera.lookAt( mesh.up );

//moves camera to middle of eyes 
camera.position.set(10,10,0);
if ( state.orientation !== null ) {

     object.quaternion.copy( state.orientation );

 }

if ( state.position !== null ) {

     object.position.copy( state.position ).multiplyScalar( scope.scale );

 }
 /* INSIDE UPDATE CYCLE */

// mesh.rotation.y+=0.1;
controls.update();

//resets bone position to default
mesh.skeleton.bones[ neckVRControlBone ].position.set(neckInitPosition.x,neckInitPosition.y,neckInitPosition.z) ;


//ROTATION SWAP
mesh.skeleton.bones[ neckVRControlBone ].rotation.x = pivot.rotation.y;

mesh.skeleton.bones[ neckVRControlBone ].rotation.y = - pivot.rotation.z;

mesh.skeleton.bones[ neckVRControlBone ].rotation.z = - tempRotation;
主js脚本

//add camera to eye
mesh.skeleton.bones[ 22 ].add(camera);

//resets camera rotation
camera.rotation.set(0,0,0);

//looks at mesh up direction to face front
camera.lookAt( mesh.up );

//moves camera to middle of eyes 
camera.position.set(10,10,0);
if ( state.orientation !== null ) {

     object.quaternion.copy( state.orientation );

 }

if ( state.position !== null ) {

     object.position.copy( state.position ).multiplyScalar( scope.scale );

 }
 /* INSIDE UPDATE CYCLE */

// mesh.rotation.y+=0.1;
controls.update();

//resets bone position to default
mesh.skeleton.bones[ neckVRControlBone ].position.set(neckInitPosition.x,neckInitPosition.y,neckInitPosition.z) ;


//ROTATION SWAP
mesh.skeleton.bones[ neckVRControlBone ].rotation.x = pivot.rotation.y;

mesh.skeleton.bones[ neckVRControlBone ].rotation.y = - pivot.rotation.z;

mesh.skeleton.bones[ neckVRControlBone ].rotation.z = - tempRotation;

2015年10月28日更新: 为了简化,经过一些额外的调试,这不是一个夹紧问题

重申的问题是:

将VR控件映射到具有不同HMD/硬纸板轴配置的对象,并保持正确的旋转规则。 对象轴的示例: *x-up *y深度 *z边

交换旋转,只需
object.rotation.x=object.rotation.z
结果是,在更新控件后,向一侧旋转会在45º后产生不希望的旋转

每个轴的旋转规则不同:

  • x旋转直到PI,然后反转信号并保持在原来的方向上变化
  • y旋转直到PI/2,然后反转方向(增加时,开始减少)
  • z等于x
更改了
webvr polyfill.js
,并用以下内容修复了键盘/鼠标:

MouseKeyboardPositionSensorVRDevice.prototype.getState = function() {
   // this.euler.set(this.phi, this.theta, 0, 'YXZ');
   this.euler.set( this.theta , 0, - this.phi, 'YXZ');
但没有类似于其他控制器(HMD、硬纸板等)的线路。 也许用户可以使用旋转顺序和贴图会更好。 谢谢


-在js控制台中尝试设置
swappedAxis=true
,然后旋转颈部。

您遇到的主要问题是因为您使用的是Euler旋转。使用四元数可以避免此问题

此外,网格上的轴看起来是翻转的,因此必须对此进行说明

不要设置旋转的组件,只需设置四元数:

mesh.skeleton.bones[neckVRControlBone].quaternion.set(
    pivot.quaternion.y,
    -pivot.quaternion.z,
    -pivot.quaternion.x,
    pivot.quaternion.w
);

示例不起作用问题是什么?我使用了webvr polyfill。VR HMD的旋转没有限制。你说得对。仅在使用鼠标/键盘上/下查看时有限制。但经过额外的调试后,我意识到问题是另一个。我更新了我的问题!