0

我使用three.js Canvas Renderer API() 开发了Panaroma,我在旋转时观察到破碎和震动的角落,我怎样才能使我的过渡\输出平滑?

在此处输入图像描述

在此处输入图像描述

代码:

全景.html

<!doctype html>
<html>
<head>
<title>A Simple Panaroma</title>
<script src="three.js"></script>
<script src="panaroma.js"></script>
<link rel="stylesheet" href="panaroma.css"></link>
</head>
<body></body>
</html>

panaroma.css

html,body{
    margin:0px;
    padding:0px;
    border:0px;
    overflow:hidden;
    width:100%;
    height:100%;
}

panaroma.js

function Panorama() {
    var width = window.innerWidth,
        height = window.innerHeight; // Capture the width and height of window
    var scene = new THREE.Scene(); // Create a Scene
    var camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000); // Create a Camera width aspect ratio,zoomin and zoomout properties
    var renderer = new THREE.CanvasRenderer(); // Create a Canvas Renderer as we are using a canvas here
    var textureCanvas, materials, lon = 90,
        onMouseDownLon = 0,
        lat = 0,
        onMouseDownMouseX = 0,
        onMouseDownMouseY = 0,
        onMouseDownLat = 0,
        phi = 0,
        theta = 0,
        target = new THREE.Vector3(),
        isUserInteracting = false;

    //Set size of render

    renderer.setSize(width, height);


    addTextureCanvas();
    document.addEventListener('mousedown', onDocumentMouseDown, false);
    document.addEventListener('mousemove', onDocumentMouseMove, false);
    document.addEventListener('mouseup', onDocumentMouseUp, false);
    document.addEventListener('mousewheel', onDocumentMouseWheel, false);

    function addTextureCanvas() {
        //Create a Canvas Element
        textureCanvas = document.createElement('canvas');

        addMaterials();
    }

    function addMaterials() {
        materials = [



        loadTexture('http://img528.imageshack.us/img528/3751/righthf.jpg'), // Right
        loadTexture('http://img827.imageshack.us/img827/931/leftag.jpg'), // Left
        loadTexture('http://img94.imageshack.us/img94/4195/topfz.jpg'), // Top
        loadTexture('http://img856.imageshack.us/img856/1772/bottomi.jpg'), // Bottom
        loadTexture('http://img266.imageshack.us/img266/8257/backkmk.jpg'), // Back
        loadTexture('http://img189.imageshack.us/img189/3938/frontnmb.jpg') // Front


        ];
        addToScene();
    }

    function addToScene() {
        mesh = new THREE.Mesh(new THREE.CubeGeometry(100, 100, 100, 7, 7, 7), new THREE.MeshFaceMaterial(materials));
        scene.add(mesh);
        mesh.scale.x = -1.6;
        document.body.appendChild(renderer.domElement);
    }

    function loadTexture(path) {

        var texture = new THREE.Texture(textureCanvas);
        var material = new THREE.MeshBasicMaterial({
            map: texture,
            overdraw: true
        });

        var image = new Image();
        image.onload = function () {

            texture.needsUpdate = true;
            material.map.image = this;

            render();

        };
        image.src = path;

        return material;

    }

    function render() {

        lat = Math.max(-85, Math.min(85, lat));
        phi = (90 - lat) * Math.PI / 180;
        theta = lon * Math.PI / 180;

        target.x = Math.sin(phi) * Math.cos(theta);
        target.y = Math.cos(phi);
        target.z = Math.sin(phi) * Math.sin(theta);

        camera.lookAt(target);
        renderer.render(scene, camera);
    }

    function onDocumentMouseDown(event) {

        event.preventDefault();

        isUserInteracting = true;

        onPointerDownPointerX = event.clientX;
        onPointerDownPointerY = event.clientY;

        onPointerDownLon = lon;
        onPointerDownLat = lat;

    }

    function onDocumentMouseMove(event) {

        if (isUserInteracting) {

            lon = (onPointerDownPointerX - event.clientX) * 0.1 + onPointerDownLon;
            lat = (event.clientY - onPointerDownPointerY) * 0.1 + onPointerDownLat;
            render();

        }

    }

    function onDocumentMouseUp(event) {

        isUserInteracting = false;
        render();

    }

    function onDocumentMouseWheel(event) {

        camera.fov -= event.wheelDeltaY * 0.05;
        camera.updateProjectionMatrix();

        render();

    }
}

document.addEventListener("DOMContentLoaded", function () {
    new Panorama();
});

如何使输出平滑?任何建议都受到高度赞赏。

4

1 回答 1

2

增加 CubeGeometry 上的分割。

mesh = new THREE.Mesh( new THREE.CubeGeometry( 100, 100, 100, 16, 16, 16 ), new THREE.MeshFaceMaterial( materials ) );

如果您想了解有关此问题的更多信息,请阅读本文

提示:避免这种情况:

mesh.scale.x = -1.6;

相反,保持比例为正,并像这样定义你的材料:

var material = new THREE.MeshBasicMaterial({
    map: texture,
    side: THREE.BackSide,
    overdraw: true
});
于 2012-12-15T17:28:01.060 回答