3d ';应用';或';烘焙';轮换到三人组
在我的应用程序中,我试图通过从设备定向API获得的旋转来旋转对象组 在某个时刻,我想校准对象的旋转,使其看起来与相机的方向相同。(具有旋转值(0,0,0)!) 但是因为我是通过旋转来设置对象的3d ';应用';或';烘焙';轮换到三人组,3d,three.js,rotation,3d,Three.js,Rotation,在我的应用程序中,我试图通过从设备定向API获得的旋转来旋转对象组 在某个时刻,我想校准对象的旋转,使其看起来与相机的方向相同。(具有旋转值(0,0,0)!) 但是因为我是通过旋转来设置对象的 var euler = new THREE.Euler(x, y, z, 'ZXY'); // angles come from Device Orientation this.object.setRotationFromEuler(euler); 我的对象始终采用我的设备的绝对旋转。为了校准它,我想在
var euler = new THREE.Euler(x, y, z, 'ZXY'); // angles come from Device Orientation
this.object.setRotationFromEuler(euler);
我的对象始终采用我的设备的绝对旋转。为了校准它,我想在我的组上设置一个旋转,然后将旋转矩阵“应用”到该组。有效地将其旋转值x、y、z设置为0,这样我可以使用绝对值再次设置它们,但组应相对于校准旋转旋转
我尝试过类似的方法,但由于我的团队没有几何图形,所以无法工作。我是否必须遍历每个子对象并将旋转应用于每个几何体,或者是否有任何方法将旋转状态设置为组的“基准”
我唯一能想到的另一个解决方案是,根据校准请求保存当前旋转值,并始终相对于这些值旋转,但如果有这样一种方法,那就太好了。想到三种方法 第一,正如您已经说过的,您可以将校准的旋转应用于组中的所有几何体,但在这种情况下,这听起来并不正确,因为您没有校准模型本身 您还提到了下一个,即在将设备方向值应用于模型之前,使用一些校准偏移调整设备方向值。这可能是最简单的选项,允许您在将值输入模型之前添加其他内容,如衰减和传感器融合(考虑从加速度预测运动)等 我能想到的最后一种方法是使用另一个组作为校准参考,并在执行校准时更新其旋转。这可能看起来像这样:
var reference = new THREE.Group();
var model = new THREE.Group();
// your model goes here
model.add(new THREE.Mesh(
new THREE.BoxGeometry(1,1,1),
new THREE.MeshStandardMaterial()
));
reference.add(model);
scene.add(reference);
// (not shown) model-rotation will always be updated with
// unmodified device-orientation data.
// for calibration, set rotation of the reference-group to the
// inverse of the current global rotation of the model.
// That way the overall rotation of the model should be zero for the
// current value from device-orientation (using the world/global rotation
// makes this repeatable regardless of previous calibration-values)
function onCalibration() {
reference.quaternion
.copy(model.getWorldQuaternion())
.inverse();
}