Javascript three.js:跳跃式动画(由于浮动不精确?)
我正在openlayers地图顶部的单独画布上使用three.js。我同步地图视图和three.js相机(它看起来垂直于地图)的方式很好,如下所示:Javascript three.js:跳跃式动画(由于浮动不精确?),javascript,three.js,Javascript,Three.js,我正在openlayers地图顶部的单独画布上使用three.js。我同步地图视图和three.js相机(它看起来垂直于地图)的方式很好,如下所示: function updateThreeCam( group, // three.js group — has camera in it view, // ol3 view map // ol3 map ) { // get visible part of map const extent = getView
function updateThreeCam(
group, // three.js group — has camera in it
view, // ol3 view
map // ol3 map
) {
// get visible part of map
const extent = getViewExtent(view, map);
const h = ol.extent.getHeight(extent);
const mapCenter = ol.extent.getCenter(extent);
// calculates how for away from the ground the camera has to
// be to match the currently visible part of the map
const camDist = h / (2 * Math.tan(constants.CAM_V_FOV_RAD / 2));
camera.updateProjectionMatrix(); // needed?
group.position.set(...mapCenter, camDist);
group.updateMatrixWorld();
}
但是,当我设置一个对象从相机前面向下飞行到地面的动画时,运动并不平滑:垂直运动跳跃很多
这是动画代码:
// construct a spline to animate along
const waypoints = [
objStartPosition,
objEndPosition,
];
const pathSpline = new THREE.CatmullRomCurve3(waypoints);
// const pathSpline = new THREE.LineCurve3(...waypoints);
startTime = Date.now();
// [...]
function animate() {
const diff = Date.now() - startTime;
const t = diff / aniDuration;
// sample curve at `t`
const pos = pathSpline.getPointAt(t);
// update position
obj.position.copy(pos);
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
奇怪的是,我没有真正看到采样位置的跳跃:
正如你所见,地图坐标往往是非常大的数字。这就是为什么我认为这可能是一个浮点精度问题把所有东西除以1000似乎确实有帮助。这其中只有两个新问题:
- 这种缩短效应已经不再那么剧烈/不现实了
- 平移不再按预期工作:地面上的矩形不会停留在其位置
试试three.js dev分支
@WestLangley yep,它与dev
版本配合得很好这只是你的一种预感,或者你还有什么可以分享的见解吗。