【问题标题】:how to change starting position of a sphere in threejs如何在threejs中更改球体的起始位置
【发布时间】:2022-02-08 20:33:58
【问题描述】:

我使用旋转的three.js 创建了一个3D 地球,但问题是它开始在海洋上空旋转。 我尝试使用 matrixWorld 更改起始位置,但没有更改任何内容 有人可以帮忙吗? 这是我的js:

... const earthgeometry = new THREE.SphereGeometry(0.344,64,32);

            const eatrhmaterial = new THREE.MeshPhongMaterial({
                roughness: 1,
                metalness:0,
                map: THREE.ImageUtils.loadTexture('static/img/earthmap1k.jpg'),
                bumpMap: THREE.ImageUtils.loadTexture('static/img/earthbump.jpg'),
                bumpScale: 0.3,
            });

            const earthmesh = new THREE.Mesh(earthgeometry,eatrhmaterial);
            earthmesh.position.set (0.49,0.035,0.58);
            earthmesh.matrixWorld.setPosition(new THREE.Vector3(100, 100, 100));

...

【问题讨论】:

  • 设置 Y 轴旋转的初始值为 Math.PI * 0.5,例如。 earthmesh.rotation.y = Math.PI * 0.5;
  • 你能详细说明一下这个问题吗?它从哪个海洋开始旋转,你有截图吗?我假设你正在旋转你的地球材料,并且你有一个海洋的辅助球体
  • 嗨@Mouhcin,如果这个或任何答案解决了您的问题,请点击复选标记考虑accepting it。这向更广泛的社区表明您已经找到了解决方案,并为回答者和您自己提供了一些声誉。没有义务这样做。

标签: three.js


【解决方案1】:

与设置位置的方式相同,您可以设置对象的旋转。

const earthgeometry = new THREE.SphereGeometry(0.344,64,32);

const earthmaterial = new THREE.MeshPhongMaterial({
//material definition here
});

const earthmesh = new THREE.Mesh(earthgeometry,earthmaterial);
earthmesh.position.set (0.49,0.035,0.58);
earthmesh.rotation.set (0,1.1,0);//or any other values

记住:

  1. 旋转以弧度为单位:360° = 2*Math.PI
  2. Y轴是垂直的

【讨论】:

  • 感谢您的快速回答
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多