three.js:全景查看器中的图像波纹

时间:2018-11-01 20:50:38

标签: three.js panoramas

当前,我让自己熟悉three.js,并创建了一个简单的全景查看器: http://webentwicklung.ulrichbangert.de/threejs-image-on-sphere-inside.html 不幸的是,支柱的垂直边缘是波纹状的。 使用Panorama Studio的全景查看器时,一切都很好: http://ulrichbangert.de/heimat/Halberstadt/2018-06-10_Halberstadt_Dom_Panorama.html

    var width = window.innerWidth,
        height = window.innerHeight;

    var scene = new THREE.Scene();
    scene.add(new THREE.AmbientLight(0x333333));
    var light = new THREE.DirectionalLight(0xffffff, 1);
    light.position.set(5, 3, 5);
    scene.add(light);

    var camera = new THREE.PerspectiveCamera(45, width / height, 0.01, 1000);
    camera.position.z = 1;
    camera.fov = Math.max(100, Math.min(200, camera.fov));
    camera.updateProjectionMatrix();

    var renderer = new THREE.WebGLRenderer();
    renderer.setSize(width, height);
    document.body.appendChild(renderer.domElement);

    var loader = new THREE.TextureLoader();
    loader.load('images/panorama.jpg', function (texture) {
        texture.anisotropy = renderer.getMaxAnisotropy();
        var material = new THREE.MeshBasicMaterial({
            map: texture
        });
        var sphere = new THREE.Mesh(
            new THREE.SphereGeometry(20, 32, 32),
            material
        );
        sphere.scale.x = -1;
        sphere.rotation.x = -0.5;
        scene.add(sphere);
        var animate = function () {
            requestAnimationFrame(animate);
            sphere.rotation.y += 0.002;
            renderer.render(scene, camera);
        };
        animate();
    });

这是怎么了?

1 个答案:

答案 0 :(得分:1)

尝试将更多细分添加到SphereGeometry。现在,您有32个纬度和经度细分,这会对纹理产生一些难看的直线变形。如果您执行new THREE.SphereGeometry(20, 100, 100)之类的操作,则在纹理贴图时将获得更好的保真度。

enter image description here