我正在构建一个 Three.js 应用程序(React 模板,如果它很重要的话)。我有这个 3D 对象模型,它应该像应用程序中的行星地球一样。我有这个空间站模型。我想通过每隔一秒给出一些特定的坐标来旋转空间站到世界各地。我的问题是:
例如,如果我有以下坐标,如何将空间站放置在伦敦上方:
long: 45.926013877299
and lat: 46.524648101056
(随机的)
这是我加载对象的方式:
const loader = new GLTFLoader();
loader.load("path/to/model", function (gltf) {
scene.add(gltf.scene);
});
Vector3 有一个名为Vector3.setFromSphericalCoords(radius, phi, theta) https://threejs.org/docs/index.html#api/en/math/Vector3.setFromSphericalCoords。您可以使用它将距离、纬度和经度转换为空间中的 X、Y、Z 点:
const radius = 100; // Distance from center of Earth
const polar = 180 - (lat + 90);
const phi = THREE.MathUtils.degToRad(polar);
const theta = THREE.MathUtils.degToRad(long);
mesh.position.setFromSphericalCoords(radius, phi, theta);
// Final result
console.log(mesh.position.toArray());
Notice phi
and theta
必须以弧度为单位,而不是度数,所以我必须转换它们。我还必须更改纬度的值。这是因为phi
北极的测量值为 0°,南极的测量值为 180°。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)