The CanvasRenderer creates panoramic views with sharp edges

I recently created a Panorama using the Canvas Renderer API from three.js, but I'm facing issues with broken and jagged corners during rotation. How can I ensure that my transitions and output are smooth?

Code:

panorama.html

<!doctype html>
<html>
<head>
<title>A Simple Panorama</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(); 
    var camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000); 
    var renderer = new THREE.CanvasRenderer(); 
    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;

    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() {

        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();
});

If you have any suggestions on how to achieve smooth output, please feel free to share!

Answer №1

Optimize the resolution of your CubeGeometry for improved performance.

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

If you are interested in delving deeper into this topic, check out this informative article.

Remember to steer clear of this approach:

mesh.scale.x = -1.6;

Instead, maintain a positive scale and set up your material as follows:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Incorporating imports disrupts the script configuration in Nuxtjs 3

Issues arise when utilizing the import statement within the context of <script setup>, causing subsequent code to malfunction. After installing the @heroicons package and importing it as a component in the <template>, all code below the import ...

Realistic rendering using Three JS

I recently created a scene using the three.js editor and tried to replicate the same result in my own project using R3F. I encountered some differences between the two projects. Check out a screenshot of my project's scene here And compare it with t ...

Unable to transmit the element identifier information through ajax

Whenever I attempt to pass id data through ajax, I encounter an undefined variable error. The ajax function works smoothly with form data, but the issue arises when trying to extract the id value. Below is the PHP/HTML code snippet: <ul class="sub-men ...

Leveraging a service variable in Angular

Is there a way to access data shared in a service within a directive? Let's say we have a directive called resultsDirective, and a service named dataService. How can we retrieve a variable from the service within the directive? angular.module("someMo ...

Maximum opacity in Three.js fog

My Current Endeavor: I am in the process of developing a lightweight GIS application with topography. One feature I want to implement is atmosphere haze. The Code I'm Working With: (Please bear with me as I have multiple scenes) fogColor = new T ...

What is the method for determining the gaps between cells in a grid-based puzzle game similar to Sudoku?

this is my current code and it's successfully functioning var cellSize:Number = 36; var cellGap:Number = 4; var row:Number; var col:Number; for (var a:int = 0 ; a < puzzleSTR.length ; a++) { col = a % 9; row = Math.floor(a / 9); ...

Enhanced SSL connectivity features in Meteor version 1.8.1

My development server is running on localhost (Windows 10 Pro x64 build 1903) and will eventually be moved to the production environment (Galaxy). To enable authentication through Facebook or Google, HTTPS is required. I configured Nourharidy Meteor SSL on ...

Toggling a div updates the content of a different div

I am looking to make the content within <div class="tcw-content"> dynamically change when a different div is clicked. I have little experience with Ajax, so I'm wondering if there are alternative ways to accomplish this using JS/CSS. If anyone h ...

Is there a way to make the checkbox and corresponding text display on a single line within my code snippet?

Bootstrap text-truncate is causing the checkbox and text to appear on separate lines in the following example. How can I adjust it to have the text right after the checkbox? <!DOCTYPE html> <html> <head> <meta charset="UTF-8" / ...

The placeholder within my input moves up and down when switching the input type from password to text

Currently, I am encountering an issue with the styling of a standard input element in React. Specifically, the placeholder text moves up and down by about 2px when viewed on Chrome, while there are no problems on Safari. How can I go about resolving this i ...

The difference between invoking a method directly and utilizing a function to invoke a method

Imagine we have a method inside a class that looks like this class Blog extends Component { postClicked = (id) => { this.setState({selectedPostId: id}) } render () { const newPosts = this.state.posts.map(el => { return & ...

What steps can be taken to prolong the duration of a service?

As a newcomer to angularjs, I am struggling to find documentation or examples on how to extend a basic service in order to utilize its methods from other services. For example, consider the following basic service: angular.module('myServices', [ ...

What could be the reason why I am unable to load the ejs file?

https://i.stack.imgur.com/91bPg.png Issue: Unable to find the "index.ejs" view in the views directory ...

Utilizing the change function in conjunction with that

My attempt at creating a simple function to implement the change function didn't go as planned:/ What I am trying to achieve: 1- When a cost checkbox is checked, assign the corresponding cost (e.g., cost1.checked ? cost1 = 10 : 0) 2- Calculate and di ...

Adding choices to a dropdown menu

This issue is connected to the question about Adding options to a <select> using jQuery?, but it focuses on a different aspect. The problem I'm facing is the inability to add option elements to a select in IE8. Interestingly, when switching the ...

Generating JSON data on the fly using D3.js scripting

I am attempting to create a JSON object dynamically by pulling data from an array in D3 JavaScript. (The code below is not the exact one I used, but similar) let radius = [10,20,30]; let jsonradius = '[{'; for (let i = 0; i < radius.le ...

Utilizing AngularJS: Transforming JSONP information into HTML

I'm relatively new to utilizing $http and fetching data from various websites. My main query is, how can I convert JSONP into HTML? Specifically, when using $http to request the Atari Wikipedia page, the content is displayed with and HTML elements. ...

Tips for auto-saving data in Laravel with AJAX after a few seconds?

I've set up the article post section in my project. I want to automatically save data as a draft in my articles table when creating a new post. I have included the blade file with a form and ajax code, but the ajax code doesn't seem to be working ...

Encoding a two-dimensional array into JSON format

In my PHP script, I am querying a database and formatting the results as JSON: $query = mysql_query($sql); $rows = mysql_num_rows($query); $data['course_num']=$rows; $data['course_data'] = array(); while ($fetch = mysql_fetch_assoc($q ...

Setting a Vue child component class directly from its parent component

In my Vue component, I have multiple child components that are inputs of the same type. The number of inputs can vary depending on the user, but there is a rule that at least one input must be filled. For example, there could be 5 inputs with 4 of them emp ...