The method .makePerspective() in THREE.Matrix4 has been updated with a new signature. Make sure to refer to the documentation for more information

Attempting to run a functional three.js code using release 119 of three.js (instead of r79) has resulted in an error being thrown by the previously functioning code:

THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.

There appears to be only one Google search result related to this issue (this question). While I have reviewed the documentation, I could not find any mention of makePerspective. How can I resolve the following code (which displays some dots and allows zooming in and out)? Also referencing enter link description here.

container = document.createElement('div');
document.body.appendChild(container);
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.set(0, 0, 150);
scene = new THREE.Scene();
scene.add(camera);
renderer = new THREE.WebGLRenderer({
  clearAlpha: 1
});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x228B22, 1);
document.body.appendChild(renderer.domElement);

// Define a standard Circle
circle = new THREE.CircleGeometry(1, 20);

var max = 50;
var min = -50;
for (var i = 0; i < 100; i++) {
  var object = new THREE.Mesh(circle.clone(), new THREE.MeshBasicMaterial({
    color: new THREE.Color('yellow'),
    opacity: 0.5
  }));
  object.position.x = Math.random() * (max - min) + min;
  object.position.y = Math.random() * (max - min) + min;
  object.position.z = 0;
  scene.add(object);
}

document.addEventListener('wheel', onDocumentMouseWheel, false);

function onDocumentMouseWheel(event) {
  console.log("mousewheel");
  var fovMAX = 100;
  var fovMIN = 1;
  camera.fov -= event.wheelDeltaY * 0.05;
  camera.fov = Math.max(Math.min(camera.fov, fovMAX), fovMIN);
  camera.projectionMatrix = (new THREE.Matrix4()).makePerspective(camera.fov, window.innerWidth / window.innerHeight, camera.near, camera.far);
}


animate();

function animate() {
  requestAnimationFrame(animate);
  renderer.render(scene, camera);
}
<body>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r119/three.min.js"></script>
</body>

Answer №1

To find the Matrix4 class, simply navigate to it and then proceed to Matrix4.makePerspective. However, it is recommended not to call it manually; instead, use

PerspectiveCamera.updateProjectionMatrix()
:

container = document.createElement('div');
document.body.appendChild(container);
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.set(0, 0, 150);
scene = new THREE.Scene();
scene.add(camera);
renderer = new THREE.WebGLRenderer({
  clearAlpha: 1
});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x228B22, 1);
document.body.appendChild(renderer.domElement);

// Define a standard Circle
circle = new THREE.CircleGeometry(1, 20);

var max = 50;
var min = -50;
for (var i = 0; i < 100; i++) {
  var object = new THREE.Mesh(circle.clone(), new THREE.MeshBasicMaterial({
    color: new THREE.Color('yellow'),
    opacity: 0.5
  }));
  object.position.x = Math.random() * (max - min) + min;
  object.position.y = Math.random() * (max - min) + min;
  object.position.z = 0;
  scene.add(object);
}

document.addEventListener('wheel', onDocumentMouseWheel, false);

function onDocumentMouseWheel(event) {
  var fovMAX = 100;
  var fovMIN = 1;
  camera.fov -= event.wheelDeltaY * 0.05;
  camera.fov = Math.max(Math.min(camera.fov, fovMAX), fovMIN);
  camera.updateProjectionMatrix();
}


animate();

function animate() {
  requestAnimationFrame(animate);
  renderer.render(scene, camera);
}
<body>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r119/three.min.js"></script>
</body>

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

Exploring the potential of utilizing functions in express.js to take advantage of the "locals"

Having experience with Rails/Sinatra, I am accustomed to using helper functions in my view files. However, incorporating this functionality into express.js has proven to be quite challenging. You can include locals automatically like this... app.set("nam ...

HTML - Selecting Different Values in One Drop Down Based on Another Drop Down

When selecting "First Year" in the initial drop-down menu, the options "Sem1" and "Sem2" should be displayed in the second drop-down menu. Similarly, when choosing "Second Year" in the first drop-down menu, the choices "Sem3" and "Sem4" should appear in th ...

span element causing border-spacing problem

Is there a way to adjust the spacing between these borders? I've tried using border-spacing but it doesn't seem to be working. {{#each spacing}} <span class='space'> {{business}} ({{Count}}) </span> {{/each}} CSS .spac ...

What is the process for associating JSON reponses with button actions on a webpage?

I developed a JavaScript script that interacts with a Tableau server API to handle running jobs. The script presents the retrieved jobs on a web page, along with corresponding buttons that enable users to terminate specific jobs. While the script function ...

Bootstrap Tags Input is unable to function properly with data stored locally

I am currently working on developing a Project Manager tool that allows for the addition of multiple individuals to a single project. To accomplish this, I decided to incorporate the use of Bootstrap Tags Input by following the examples provided for Typeah ...

Guide to connecting two separate components from distinct pages in React/MUI

My setup involves two pages: Appbar.js, where I have a top appbar and a Navigation Menu Icon Button that triggers the display of my Drawer (Material UI) in TempDrawer.js. Initially, everything worked fine when all the code was placed in the Appbar.js file ...

Is it possible to receive returned string values using fetch()?

I have implemented a fetch method in my separate register.js file to handle registration on the front end. However, I am encountering an error when trying to POST the data and receive the following message in the browser console: "Uncaught (in promise) Syn ...

Utilizing an alpha mask on a threejs mesh to create cast shadows

When attempting to have a single plane with an alpha mask cast shadows, I encountered an issue where the shadow was being cast for the entire plane instead of applying the alpha mask as intended. After some research, I discovered that adding a customDepth ...

The ng-click functionality is not functioning as expected within the directive

Take a look at this snippet of my HTML: <section ng-controller="GalleryController as gallery"> <nav footer-directive></nav> </section> This is the GalleryController I'm using: angular .module('myapp') ...

THREE.JS: Organizing Objects into Multiple Groups

Currently, I am in the process of learning THREE.js and attempting to create a playable Rubik's cube. My goal is to rotate a face as a whole instead of manipulating each cube individually. I have tried placing the cubes within a THREE.Group, but the ...

The proper way to define an event delegator's syntax

Typically, when you want to handle a button click event, you would do so like this: $(document).ready(function() { $("button").click(function() { doSomething(); }); }); However, in the scenario of an event delegator, you may need to respon ...

Tips for updating CSS styles for multiple innerHTML elements using a JavaScript for loop

<div id="test"></div> <script type="text/javascript"> window.names=["jin kazama", "nina williams"]; window.values=[25, 37]; len=names.length for (var i = 0; i < len; i++) { document.getElementById('test').innerHTML+ ...

What is the process for making an Ajax request in Rails?

I'm attempting to send a variable through jQuery using the POST method, saving it in a controller, and then utilizing that same variable in Rails HTML to query a table. It seems like the variable isn't being passed to the controller. jQuery: v ...

Tips for replacing spaces with &nbsp; in a string using ReactJS and displaying it in HTML

<div className="mt-2 font-sidebar capitalize"> {item.title} </div> item.title can vary and be any string retrieved from the backend, such as "all products", "most liked", "featured items", etc. I am looking for a solution to subst ...

How can we extract Euler angles from Trackball Controls in Three.js?

I am currently implementing the three.js trackball controls to allow rotation around my object. However, I am looking for a way for the view to automatically rotate slowly around the vertical axis when the user is not actively using the trackball. Does an ...

Tips for saving user input from an HTML form into a database using PHP, and then transferring it to a variable in JavaScript

I've been working on a Wordpress project that involves two separate pages. The first page has a form for users to submit their name, which is then stored in a custom table in the database. After submitting the form, the user is redirected to another p ...

Having difficulty specifying numerical entries only

I have been attempting to create an input field that only accepts numbers, but for some reason it still allows letters to be entered. Why is this happening? <input type="number" pattern="[0-9]" ...

"Discover the power of Algolia's docSearch feature

Currently, I am working on integrating Algolia DocSearch into my docusaurus project. After obtaining the api key and api id from Algolia, I am unsure of the next steps to take. I would appreciate guidance on the necessary procedures that need to be followe ...

"Troubleshooting: Why is my AngularJS ng-click not triggering the function

My custom directive fetches a navigation block from a webservice call. I am attempting to click on a navigation link that has an "ng-click" attribute set, which should call the specified function. However, the function is not being executed. Below is my r ...

Conceal HTML elements from the bottom as new content is being added dynamically

I am currently working on a comments feed feature. By default, only the first four comments are displayed, with an option to show more when clicking the "show more" anchor. The issue I'm facing is that if new comments are dynamically added, the CSS hi ...