简体   繁体   English

在坐标 3D object model in Three.js 上放置一个点

[英]Place a point upon coordinates on a 3D object model in Three.js

I am building a Three.js App (React Template, if it's important).我正在构建一个 Three.js 应用程序(React 模板,如果它很重要)。 I have this 3D object model that should act like the Pl.net Earth in app.我有这个 3D object model 应该像应用程序中的 Pl.net 地球一样。 And I've got this space station model. I wanna rotate the station around the world by giving some specific coordinates every other second.我有这个空间站 model。我想通过每隔一秒给出一些特定坐标来围绕世界旋转空间站。 My question is:我的问题是:

How can I place the space station above London, for example, if I have this coordinates:我怎样才能把空间站放在伦敦上方,例如,如果我有这个坐标:
long: 45.926013877299 and lat: 46.524648101056 (random) long: 45.926013877299lat: 46.524648101056 (随机)

This is the way I load the object:这是我加载 object 的方式:

const loader = new GLTFLoader();

loader.load("path/to/model", function (gltf) {
  scene.add(gltf.scene);
});

A Vector3 has a method called Vector3.setFromSphericalCoords(radius, phi, theta) . Vector3 有一个名为Vector3.setFromSphericalCoords(radius, phi, theta)的方法。 You can use this to convert your distance, lat, & long into an X, Y, Z point in space:您可以使用它来将您的距离、纬度和经度转换为空间中的 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 I had to change the value of latitude.请注意,我必须更改纬度的值。 This is because phi is measured as 0° at the North Pole, and 180° at the South Pole.这是因为phi在北极测量为 0°,在南极测量为 180°。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM