Troubleshooting the Gravity Issue in Three.js and Physi.js

Attempting to rewrite a Physi.js example in my own style has been challenging. The gravity feature doesn't seem to be working properly, even though the render loop is functioning correctly and constantly firing.

You can view what I have so far here:

The original Physi.js example can be found here:

Below is the code snippet that I am currently working with:

var ground = {},
    box = {},
    boxes = [],
    ground = {},
    projector,
    renderer,
    scene,
    light,
    camera,
    render,
    gravity;

// Set up Physijs configurations
Physijs.scripts.worker = 'physi.js_worker.js';
Physijs.scripts.ammo = 'ammo.js';

// Initialize Projector
projector = new THREE.Projector;

// Configure Renderer
renderer = new THREE.WebGLRenderer({
    antialias: true
});
renderer.setSize( 1000, 600 );
renderer.shadowMapEnabled = true;
renderer.shadowMapSoft = true;

// Create Scene
scene = new Physijs.Scene;

// Setup Camera
camera = new THREE.PerspectiveCamera( 35, ( 1000 / 600 ), 1, 1000 );
camera.position.set( 60, 50, 60 );
camera.lookAt( scene.position );

scene.add( camera );

// Add Lighting
light = new THREE.DirectionalLight( 0xFFFFFF );
light.position.set( 20, 40, -15 );
light.target.position.copy( scene.position );
light.castShadow = true;
light.shadowCameraLeft = -60;
light.shadowCameraTop = -60;
light.shadowCameraRight = 60;
light.shadowCameraBottom = 60;
light.shadowCameraNear = 20;
light.shadowCameraFar = 200;
light.shadowBias = -0.0001;
light.shadowMapWidth = light.shadowMapHeight = 2048;
light.shadowDarkness = 0.7;

scene.add( light );

// Define Ground Properties
ground.material = new THREE.MeshLambertMaterial({
    color: 0xDDDDDD
});
ground.material = Physijs.createMaterial( ground.material, 0.8, 0.4 );
ground.geometry = new THREE.CubeGeometry( 100, 1, 100 );
ground.mesh = new Physijs.BoxMesh( ground.geometry, ground.material, 0 );
ground.mesh.receiveShadow = true;

scene.add( ground.mesh );

// Define Box Properties
box.material = new THREE.MeshLambertMaterial({
    color: 0x00FF00
});
box.material = Physijs.createMaterial( box.material, 0.4, 0.6 );
box.geometry = new THREE.CubeGeometry( 4, 4, 4 );

// Create and position 10 boxes
for( var i = 0; i < 10; i++ ){

    var pos = {},
        rot = {};

    pos.x = Math.random() * 50 - 25;
    pos.y = 10 + Math.random() * 5;
    pos.z = Math.random() * 50 - 25;
    rot.x = Math.random() * Math.PI * 2;
    rot.y = Math.random() * Math.PI * 2;
    rot.z = Math.random() * Math.PI * 2;
    box.mesh = new Physijs.BoxMesh( box.geometry, box.material );
    box.mesh.position.set( pos.x, pos.y, pos.z );
    box.mesh.rotation.set( rot.x, rot.y, rot.z );
    box.mesh.castShadow = true;

    scene.add( box.mesh );
    boxes.push( box.mesh );

};

// Rendering method
render = function(){

    scene.simulate( null, 50 );
    renderer.render( scene, camera );
    requestAnimationFrame( render );

};

// Initiate rendering
$( function(){

    $('#viewport').append( renderer.domElement );

    render();

});

Answer №1

The "physi.js_worker.js" file seems to be devoid of content, causing the web worker to initiate without being able to execute any scripts.

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

Pass the result of the callback function from the service to the component

I have integrated the WifiWizard Plugin into my Ionic 2 mobile app using Cordova. It works perfectly fine when I run it in the *.ts file of my page. Here is how my code looks: Declaring WifiWizard before @Component: declare var WifiWizard:any; Using Wif ...

Enabling Context Isolation in Electron.js and Next.js with Nextron: A Step-by-Step Guide

I've been working on a desktop application using Nextron (Electron.js + Next.js). Attempting to activate context isolation from BrowserWindow parameters, I have utilized the following code: contextIsolation: true However, it seems that this doesn&ap ...

Utilize information from a JSON Array to populate a JavaScript Array

Is there a way to link the data from the $data variable in ajax.php to the this.products[] array in store.js? Both files are separate, so how can I achieve this? The webpage displays the database data returned by ajax.php as shown below: [{"0":"100001"," ...

Using jQuery to replace the content of a div with a delay?

I am attempting to utilize jQuery to create a fade effect on an element, replace its innerHTML content, and then fade it back in once the new content has been added. I have successfully managed to replace the element's content using the .html() method ...

When utilizing div.load, jQuery and other JavaScript sources may not be defined

When you load a page using jQuery load: $("#myDiv").load("page.php",{foo: bar}); The head section is included in the index: <head> <script src="/assets/plugins/jQuery/jQuery-2.1.4.min.js"></script> <script src="/assets/plugi ...

Issues with Ajax arise once URL re-routing is activated

When loading content using AJAX and ASP.NET web-methods, the following code is used to trigger the Ajax request: var pageIndex = 1; var pageCount; $(window).scroll(function () { if ($(window).scrollTop() == $(document).height() - $(window).height()) ...

Obtain the VW/VH coordinates from an onclick action in JavaScript

With this code snippet, you'll be able to retrieve the x and y coordinates of a click in pixels: document.getElementById("game").addEventListener("click", function(event) { console.log(event.clientX, event.clientY); }); However ...

React isn't updating the on-change value despite changes being made

In my React application, there is a file called EditTodos.js that is responsible for updating the to-do list. When I click on the "Edit" button, it triggers a pop-up modal component. import React, { useState } from "react"; import { Button, Modal } from " ...

The current environment does not recognize the term 'ScriptManager'

After attempting to solve a JavaScript issue following an AJAX postback in ASP.Net by implementing some code, I encountered an unexpected error during the build process: An unexpected error occurred: The name 'ScriptManager' does not exist in th ...

The button text in Bootstrap 5 is black instead of white as shown in their demo

During the installation of Bootstrap 5, I encountered an issue where many of my buttons are displaying a black font instead of the expected white font as shown in the Bootstrap 5 Documentation For instance, the .btn-primary button on the official Bootstra ...

Combining multiple arrays into a single array using JavaScript

Forgive my beginner question, but I am just starting to learn JavaScript and I can't shake this thought. Let's use an example: Suppose we have: animals['Cat', 'Dog']; and, mood['Sad' , 'Happy']; I ne ...

Calculate the sum of object values in JavaScript when all other values in the object are identical

Recently, I've been delving into JS high array methods and encountered an array of objects featuring cost categories and values: [{category: "Bars", amount: 31231}, {category: "Transport", amount: 1297}, {category: "Utilities", amount: 12300}, {categ ...

Magento - when the page just can't take it anymore

I've encountered a problem with my Magento store. Half of the page is displayed and then it breaks. Here's the link to the page: When I check the page source, this is the code where it seems to break: <script type="text/javascript> ...

Find the two numbers within a specific range in an array using jQuery

I have two arrays and I need to check for any duplicate ranges. How can I achieve this? let startingArray = ['1', '6.1', '10', '31','6.2',3]; let endingArray = ['2', '9.9', '30&ap ...

The Value Entered in Angular is Unsaved

I have encountered an issue with my app's table functionality. The user can enter information into an input field and save it, but upon refreshing the page, the field appears empty as if no data was entered. Can someone please review my code snippet b ...

Struggling with react three fiber and encountering the error message: THREE.WebGLRenderer: Context Lost

I'm facing an issue with my dice where I'm getting the error message THREE.WebGLRenderer: Context Lost. I suspect the problem arose from switching from use-cannon to @react-three/cannon. When trying to render D4, I encounter the error. Surpris ...

Is there a way for me to access the property value utilized in the Cypress test?

I am currently working on a Cypress example that can be found at the following link: : cy.get('[data-test-id="test-example"]') .invoke('css', 'position') .should('equal', 'static') Despite my ...

Invoking a function from a higher-level parent scope within multiple layers of nested directives

I am working with a data structure that is nested infinitely. There is a top-level object containing a collection of objects, and each of these objects can also have their own collection of objects. To iterate through this tree, I have implemented the fol ...

Issue with Achieving Two-Way Binding in Angular 1.5 Component when using $ctrl

I am struggling with customizing some products using a component in my index.html. Ultimately, I need to calculate the total of selected products within the main controller "planosVoz" using two-way binding on the svaTotal property in the component control ...

What is the best way to apply a Javascript function to multiple tags that share a common id?

I am experimenting with javascript to create a mouseover effect that changes the text color of specific tags in an HTML document. Here is an example: function adjustColor() { var anchorTags = document.querySelectorAll("#a1"); anchorTags.forEach(func ...