Three JS Keep Label Size On Zoom

前端 未结 4 543
臣服心动
臣服心动 2020-12-05 16:08

I\'m working on a solar system in three.js and am curious if there is an easy way to make the labels for the planets I have below all show up the same size regardless of how

4条回答
  •  被撕碎了的回忆
    2020-12-05 16:17

    I figure you could calculate the distance from each label to the camera then come up with some sort of scaling factor based on that.

    And it's very simple. Let's say, a THREE.Sprite() object (label) is a child of a THREE.Mesh() object (planet), then in your animation loop you need to do

    var scaleVector = new THREE.Vector3();
    var scaleFactor = 4;
    var sprite = planet.children[0];
    var scale = scaleVector.subVectors(planet.position, camera.position).length() / scaleFactor;
    sprite.scale.set(scale, scale, 1); 
    

    I've made a very simple example of the Solar System, using this technique.

提交回复
热议问题