Sleek transition-ready zoom functionality for THREE JS with clickable controls

Hey there, I've been attempting to animate a transition between scenes in THREE js for quite some time now. I have successfully cleared the scene and recreated the next one, but the transition between them is proving to be quite challenging. I have created two functions:

function zoomInTransition() {
    var zInMin = 15;
    for (camera.fov; camera.fov > zInMin; camera.fov-=3) {
        camera.updateProjectionMatrix();
    }
}

function zoomOutTransition () {
    var zOutMax = 70;
    for (camera.fov; camera.fov < zOutMax; camera.fov+=3) {
        camera.updateProjectionMatrix();
    }
}

I call each function like this:

function buttonReaction(){
    for (var i in objects) {
        switch(objects[i].name) {
            case "door_1":
                zoomInTransition();
                Start(room2);
                zoomOutTransition()
                break;
            case "door_2":
                zoomInTransition();
                Start(room1);
                zoomOutTransition()
                break;
            default: 
                console.log("default");
        };
    };
}

Nevertheless, I am struggling to achieve a smooth zoom transition, as it iterates too quickly for the projection matrix updates to display properly. I'm running out of ideas... Any suggestions would be greatly appreciated. Thank you.

Answer №1

Although it may be a bit tardy, there is a solution available. By creating a helper function called "transition," you can gradually adjust the zoom level until your desired zoom is achieved. For example, if you wish to zoom in by 20 units, you would call transition which will rapidly execute 10 iterations of zooming in by 2 units consecutively, giving the appearance of a seamless transition.

//zoom function with transition
function zoomIn() {
    if(camera.fov > minZoom) {
        dom.zoomOut.css('opacity',1);
        transition(cameraZoomIn,20);
    }
    if(camera.fov-20 <= minZoom){
        dom.zoomIn.css('opacity',0.2);
    }
}

//zoom function with transition
function zoomOut(){
    if(camera.fov < maxZoom) {
        dom.zoomIn.css('opacity',1);
        transition(cameraZoomOut,20);
    }
    if(camera.fov+20 >= maxZoom){
        dom.zoomOut.css('opacity',0.2);
    }
}

//small amount of zoom
function cameraZoomIn(quantity){
    camera.fov -= quantity;
    camera.updateProjectionMatrix();
}

//small amount of zoom
function cameraZoomOut(quantity){
    camera.fov += quantity;
    camera.updateProjectionMatrix();
}

//Create a transition for the movement func (go left, up, zoom,...) where func must move with amount quantity
function transition(func, quantity) {
    var intervalTime = 15;
    //We make a small version of the same movement : move 1/10 of the original quantity every intervalTime
    var interval = setInterval(function(){func(quantity/10)}, intervalTime);
    //We stop doing the movement when we have done 10 times the small movement
    setTimeout(function(){clearInterval(interval)}, intervalTime*10)
}

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

Send functions from the back-end Node to the front-end Angular

Introduction I am currently working on a project that involves verifying email addresses within an API in order to grant users access to a restricted section. To accomplish this, I have developed backend node code with three functions built using Node and ...

The function setCustomValidity() will continue to display even after the form has been successfully filled out

My form is very simple and I am trying to validate it using the required attribute: <form name="form"> <label for="Header">Title</label> <input type="text" class="span5" name="Header" ng-model="Message.header" placeholder="Title" on ...

Entering a new row and sending information through ajax

I'm looking for some help with a web page I have that includes a particular table structure: **Check out my Table*:* <table id="staff" class="table"> <thead> <tr> <th>First Name</th> <th>Last Nam ...

Encountering issues with parsing JSON data following its transmission through an Ajax request

Client Side Once an object has been processed with JSON.stringy, it is sent in this format to a node-server via a POST request: {"id":"topFolder","parentPath":null,"name":"newProject","is":"root","children":[]} The request is sent from the client side u ...

JavaScript code to determine if a Rating is enabled for a SharePoint Online list

Currently, I am working on a JavaScript code that will allow users to provide star ratings for specific articles through a widget. One of the requirements is to first verify if the Rating feature is enabled for a particular SharePoint list. If it is enable ...

Utilizing REACT to extract values from deeply nested JSON structures

Currently, I am utilizing react to display information from properties stored in a nested JSON. While I can successfully render properties like 'name' and 'id' that are not nested, I encounter an issue when trying to access a nested pro ...

Preventing Button Click with JQuery Tooltip

I've implemented a JQuery tooltip plugin on my website and it's working great. However, I'm facing an issue where I cannot click on the input button that appears when hovering over the tooltip. It seems like the button is not truly part of t ...

Updating the web browser does not display the changes made on the page

Currently diving into the world of Angular and I've successfully cloned the repository. After installing the dependencies using npm, I have the web server up and running smoothly. Accessing the page on localhost:4000 works like a charm. Interestingly ...

How can you refresh the .replaceWith method in jQuery?

Is there a way to reset the .replaceWith function so that the html, css and javascript elements are restored to their original state? I am looking to have an icon replace the text when the user clicks on "contact", and then have the text return when the u ...

Utilize Ajax.ActionLink on a DIV by incorporating data from the Model

Although there are similar questions on this topic already, they do not address the specific issue of using values from the model as arguments for the controller. Make DIV containing AJAX ActionLink clickable Div as Ajax.ActionLink Take a look at the fo ...

Using Flask to invoke a Python function that displays an image when a button is clicked

I am currently working on developing a basic web application that allows clients to upload images, processes them on the server, and then returns the processed image to be displayed in a specific div. I attempted to use ajax for this purpose, but encounter ...

Traversing through each element using Array method

I need to create a redux function that will add a specified number n to the fourth element of an array every time a button is clicked. However, if the element is either L or M, I do not want the addition to occur. For example, starting with this initial a ...

Quantities with decimal points and units can be either negative or positive

I need a specialized input field that only accepts negative or positive values with decimals, followed by predefined units stored in an array. Examples of accepted values include: var inputValue = "150px"; <---- This could be anything (from the input) ...

Tips on arranging JSON elements based on the sequence of another JSON

Currently, I am facing a challenge with sorting a list of parks (park_list) based on both distance and area. The code snippet below successfully sorts the list by distance: sortList(index){ return function(a, b){ return (a[index] === b[index] ? 0 : ...

Adjust the color of text as you scroll

Could you provide guidance on changing the color of fixed texts in specific sections of my portfolio website? Unfortunately, I can't share my lengthy code here, but would greatly appreciate it if you could illustrate with examples. Here's a refer ...

Scrolling in iOS 8 causing flickering problem with background image

Utilizing the Supersized jQuery slider plugin to create a full-page background slider with a fade-in effect and added height for scrolling. The slider functions correctly on desktop, but upon testing on an iOS 8 iPad device, there is noticeable flickering ...

Adapt appearance according to the length of the text

Currently, I have an array that stores multiple strings based on displayed charts. My objective is to find the longest string within this array. So far, this task has been executed without any issues. The code snippet for this process is as follows: var ...

Unraveling the Mystery of jQuery Syntax

Upon reviewing jquery.ui-1.8.11.js: $.extend(Datepicker.prototype, { /* A unique class name appended to elements indicating they are configured with a date picker. */ markerClassName: 'hasDatepicker', /* For debugging purposes (if e ...

Guide on importing images from directories in Vue

As I delve into learning vue.js, a particular issue has surfaced. I am in the process of creating an SFC and encountering difficulties with loading images from the 'src / assets / logo.png' folder. Below is the code snippet: <template> & ...

Modify the main container width based on the size of the table

Would it be possible for the main container width to increase along with the table width? Is that achievable? <div class="container main-con"> <table class="table table-hover"> <tr><td></td></tr> </table> ...