Morphing Sphere into Plane

蹲街弑〆低调 提交于 2019-12-12 10:26:24

问题


Is there a way to change the SphereGeometry() object to flat plane on screen? I want to do it exactly as this site, so when you click on bottom right buttons, the view is changed. The code below is how the sphere created. Simplicity is important.

var loader = new THREE.TextureLoader();
    loader.load("js/model/map.jpg", function(texture) {
    var earthMaterial = new THREE.MeshBasicMaterial({
        map: texture,
        bumpscale: 0.05
    });
    var earthSphereGeometry = new THREE.SphereGeometry(80, 32, 32);

    earthSphere = new THREE.Mesh(earthSphereGeometry, earthMaterial);
    scene.add(earthSphere);
})

回答1:


Speaking of morphing earth-like sphere into map-like plane - geometry morphing (vertex displacement) works well. Starting with THREE.SphereBufferGeometry wouldn't work good since unwrapped polygonal sphere is not quite a plane.

But there are no such problems with THREE.PlaneBufferGeometry. To construct desired object you could use your own ShaderMaterial. Such material should compute target sphere-alike morph in vertex shader (either on CPU - then it should be passed as another attribute). Having two states smoothly mix between them using float uniform.

Here is a working example of such wrapping with 77 revision of three.js (use slider to wrap).

vec3 anglesToSphereCoord(vec2 a, float r)
{
    return vec3(
        r * sin(a.y) * sin(a.x),
        r * cos(a.y),
        r * sin(a.y) * cos(a.x)  
    );
}

void main() {
    vec2 angles = M_PI * vec2(2. * uv.x, uv.y - 1.);
    vec3 sphPos = anglesToSphereCoord(angles, 0.6);
    vec3 wrapPos = mix(position, sphPos, wrapAmountUniform);

    gl_Position = projectionMatrix * modelViewMatrix * vec4( wrapPos, 1.0 ); 
}

It is worth noticing that this object construction is sensitive to camera position. In order to hide a cut and have a nice transition at any angle you could fix camera and apply rotation in shader (rotating not geometry, but uv coordinates). Handling different projections goes there as well.



来源:https://stackoverflow.com/questions/38712632/morphing-sphere-into-plane

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!