Error: The class constructor "Scene" cannot be executed without using the keyword 'new'. Located at line 391 in the file: "physi.js" in the directory: "threejs/libs"

I have been utilizing the Physijs library with an older version of three.js and everything was functioning perfectly. However, upon downloading the latest version of three.js, I encountered issues even when attempting to add a simple plane mesh to the scene.

An error message is displayed as follows:

 Uncaught TypeError: Class constructor Scene cannot be invoked without 'new' line:391 of:file:///storage /emulated/0/threejs /learning-threejs/libs/physi .js

I am puzzled by the exact reason behind this issue. Here is my code snippet:

<html>
<head>
    <title>Example 01.01 - Basic skeleton</title>
   <script type="text/javascript" src="../libs/three.min.js"></script>
        <script type="text/javascript" src="../libs/dat.gui.js"></script>
    <script type="text/javascript" src="../libs/TrackballControls.js"></script>
    <script type="text/javascript" src="../libs/physi.js"></script>
<style>
        body {
            /* set margin to 0 and overflow to hidden, to
             use the complete page */
            margin: 0;
            overflow: hidden;
        }
    </style>
</head>
<body>
<!-- Div which will hold the Output -->
<div id="WebGL-output">
</div>
<!-- Javascript code that runs our Three.js examples -->
<script type="text/javascript">
    // once everything is loaded, we run our Three.js stuff.
    function init() {
    Physijs.scripts.worker = '../libs/physijs_worker.js';
    Physijs.scripts.ammo = '../libs/ammo.js';
    //renderer
    var renderer=new THREE.WebGLRenderer({antialias:true})
    renderer.setSize(innerWidth,innerHeight)
    renderer.setPixelRatio=devicePixelRatio
    renderer.shadowMap.enabled=true
    renderer.setClearColor(new THREE.Color(0xff00ff))
    //physijs scene
    var scene=new Physijs.Scene
    scene.setGravity(new THREE.Vector3(0,-300,-50))

//ground
var groundgeo=new THREE.PlaneGeometry(50,50)
var groundmat=new Physijs.createMaterial(new THREE.MeshBasicMaterial({color:0xd2b48c ,side:THREE.DoubleSide}))
var ground=new Physijs.PlaneMesh(groundgeo,groundmat,0)
ground.rotation.x=-0.5*Math.PI
ground.position.set(-20.0,0,0.0)
ground.receiveShadow=true 
scene.add(ground)
var camera=new THREE.PerspectiveCamera(40,innerWidth/innerHeight,0.1,10000)
camera.position.set(70,65,0)
camera.lookAt(ground.position)
scene.add(camera)
var trackballControls = new THREE.TrackballControls(camera);
trackballControls.rotateSpeed = 1.0;
trackballControls.zoomSpeed = 1.0;
trackballControls.panSpeed = 1.0;
trackballControls.staticMoving = true;
document.getElementById("WebGL-output").appendChild(renderer.domElement)
render()
var step=0
function render(){
scene.simulate(undefined,2)
trackballControls.update()
requestAnimationFrame(render)
renderer.render(scene,camera)
}}
    window.onload = init()
</script>   
</body>

Thank you in advance!

Answer №1

Physi.js is no longer supported in the latest version of three.js, but it now supports Cannon.js. Therefore, it is recommended to use Cannon.js or another modern physics library instead of physi.js.

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

React's useContext not reflecting changes when state is updated

After successfully converting my class component to a functional one with the use of useContext, I am facing some challenges in accessing and retrieving the status changes. Specifically, I have a component named input.js located at src/components/input.js. ...

Discovering if an array includes a particular value in JavaScript/jQuery

Is there a way to check if the list with the class .sidebar contains an item with data-id="1"? <ul class="sidebar"> <li data-id="1">Option 1</li> <li data-id="2"> Option 2</li> <li data-id="3"> Option 3</li&g ...

Tips for validating an email address using ReactJS

I'm currently working on customizing the email verification process for a signup form in ReactJS. My goal is to replace the default email verification with my own validation criteria. Initially, I want to ensure that the entered email address contains ...

Tips for dynamically inserting a tabbed element into a list using AngularJS

I am trying to dynamically add elements with tabs in the list, but I encounter a problem where the device info gets overridden from the last user. You can see the issue here: https://i.sstatic.net/O1uXK.jpg This is how my Tabs item looks like in HTML: & ...

Utilize the HTML canvas to sketch on an image that has been inserted

I have a HTML canvas element within my Ionic application. <canvas id="canvas" color="{{ color }}" width="800" height="600" style="position:relative;"></canvas> Within this canvas, I am loading an image. Below is the code snippet from the con ...

Having trouble receiving a response from axios

My goal is to use axios to submit a blog post and display a response message. If the response is "success," the process should proceed. For testing purposes, I am only using console.log("success ok"). However, I encountered a puzzling issue that I cannot f ...

Passing identical props to multiple children in React

When working with my React App, I decided to implement a star rating system for the posts fetched from an API and displayed on the main page. To achieve this, I created a function that utilizes a Rate component to rate each post using the ratePost action. ...

What is the best way to prevent users from clearing the value attribute of an input element?

Sample Scenario: While a user is entering information into a field, I would like to restrict the ability to delete or clear out the value, such as keeping "Friend" intact. Can this be accomplished using CSS or JavaScript? ...

Loading SVG templates dynamically in Angular can be done by utilizing a string

Is it possible to convert SVG content loaded from a server into a component template in Angular, with the ability to bind properties to it? For example, <tspan [attr.color]="textColor" ...>{{myText}}</tspan>. I have tried loading and ...

JavaScript myfunction() onclick event not functioning correctly anymore

I have experience with this method in the past, but I am encountering issues when trying to implement it on a new website. The JavaScript button I used before is still functional on the old site, so I suspect there may be an error in my code even though ...

Issue with Material UI Textfield functionality on mobile Safari browser

UPDATE: Resolved the problem by including this code in index.css input { -webkit-user-select:text;} In my application, I am using a Material UI box that contains text fields with an onChange handler. While the TextFields function correctly on most bro ...

What is the best way to extract a number from a string in JavaScript?

There are instances in HTML files where a <p> tag displays the price of a product, such as ""1,200,000 Dollar"". When a user adds this product to their cart, I want the webpage to show the total price in the cart. In JavaScript, I aim to e ...

Top guidelines for validating inherited props within React applications

Exploring a component called <Section /> which requires 3 props to function: color size title The color and size props are used for styling purposes, while the title prop is passed down to its child component <SectionTitle />. Here's an ...

Utilizing static classes in Express: A guide

As a newcomer to the realm of JavaScript, I am eager to develop a web application using the MEAN stack. To maintain some level of organization in my files, I intend to encapsulate all MongoDb-related operations within a static class and call it from my ap ...

Netlify is failing to recognize redirect attempts for a Next.js application

After successfully converting a react site to utilize next.js for improved SEO, the only hiccup I encountered was with rendering index.js. To work around this, I relocated all the code from index to url.com/home and set up a redirect from url.com to url.co ...

"Encountering issue with undefined request body in Node Express on AWS Lambda

My current project involves using AWS Amplify to create Node Express REST API endpoints. I recently implemented a new endpoint, but I am encountering an issue where the request body is showing as undefined. I have been unable to pinpoint where I may have ...

Implementing dynamic classes for each level of ul li using JavaScript

Can anyone help me achieve the goal of assigning different classes to each ul li element in vanilla Javascript? I have attempted a solution using jQuery, but I need it done without using any libraries. Any assistance would be greatly appreciated! con ...

Display one component multiple times across various webpages with unique text each time

I'm currently exploring React and attempting to render a single component in various HTML files within an existing project, each with different text content. Here's what I have in mind: class CtaSection extends React.Component{ render(){ ...

Having issues with the functionality of the jQuery HTML function

I'm working on this jQuery code snippet: $('#wrapper').html('<img src="/loading.gif">'); var formdata = $("#validateuserform").serialize(); $.post("/userformdata.php",formdata,function(html){ if(html) ...

Having difficulty retrieving values while using async-await

Utilizing the code below has been successful for me. I managed to retrieve the data in the spread (then), returning a http200 response. Promise.all([ axios({ method: 'post', url: 'https://oauth2.-arch.mand.com/oauth2/token&a ...