"Encountered a roadblock while attempting to utilize the applyMatrix

I am currently working on running an animation using a JSON file and a custom JSON loader, not the one provided with three.js. Within the JSON file, there is an object called frames that contains multiple frames, each with shape information and a simulation_matrix consisting of data necessary for animation in the form of a 4x4 transformation matrix generated from a python script. To execute this animation, I am utilizing this code and loading a sample JSON script from here.

// This function adds static shapes successfully
parent.add_shape = function(frame) {   
    var material = new THREE.MeshLambertMaterial({
        color: frame.shape.color,
        wireframe: true,
        wireframeLinewidth: 0.1,
        opacity: 0.5
    });

    var geometry = new THREE.CylinderGeometry(frame.shape.radius, frame.shape.radius, frame.shape.height, 50, 50);
    
    parent.mesh_dict[frame] = new THREE.Mesh(geometry, material);

    var init_orientation = frame.simulation_matrix[0];
    var orienter = new THREE.Matrix4();
    orienter.elements = [];

    // Manually pushing elements from simulation_matrix to Matrix4
    for (var i in init_orientation) {
        for (var j in init_orientation[i]) { 
            orienter.elements.push(init_orientation[i][j]);
        }
    }  
    parent.mesh_dict[frame].applyMatrix(new THREE.Matrix4());
    parent.mesh_dict[frame].applyMatrix(orienter);
    parent.scene.add(parent.mesh_dict[frame]);
    parent.renderer.render(parent.scene, parent.camera); 
}

// This function applies simulation matrix to shapes for animation
parent.animate = function() {
    for (var frame in JSONObj.frames) {
        var matrix = JSONObj.frames[frame].simulation_matrix[parent.animation_counter];
        var animation_matrix = new THREE.Matrix4();
        animation_matrix.elements = [];
        
        // Pushing elements to Matrix4
        for (var i in matrix) {
            for (var j in matrix[i]) { 
                animation_matrix.elements.push(matrix[i][j]);
            }
        }

        console.log(animation_matrix);
        console.log(animation_matrix.elements);

        parent.mesh_dict[JSONObj.frames[frame]].applyMatrix(new THREE.Matrix4());   

        parent.mesh_dict[JSONObj.frames[frame]].applyMatrix(animation_matrix);                  
    }

    console.log(parent.animation_counter);
    parent.animation_counter++;

    if (parent.animation_counter == 10) { 
        parent.animation_counter = 0; 
    }

    requestAnimationFrame(parent.animate);
}

The issue arises when applying the simulation matrix to animate the shapes, as only one shape is animating unexpectedly within the loop.

Answer №1

I finally discovered the issue at hand. It turns out that all the dictionary parent.mesh_dict[] keys were incorrectly tied to a single object, rather than individual objects as needed. After some debugging, I successfully resolved the issue and everything is now working perfectly. I also want to acknowledge @WestLangley's valid point about using mesh.matrix.identity() for productivity. Thank you, I will consider this matter resolved and close the question.

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

The dictionary of parameters includes an empty value for the parameter 'imageWidth', which is of a non-nullable type 'System.Int32'

I am facing an issue with a function that executes an ajax call to an ActionResult. It sends a base64 string of an uploaded image along with some additional parameters containing information about the dimensions of the image. The data is sent to the server ...

JavaScript will not prevent PHP form submissions from executing

I am currently facing an issue with JavaScript where it displays an error window, but surprisingly does not prevent the form submission. I have been trying to figure out what exactly is causing this problem without much success. Below is the code I am work ...

As you scroll, the opacity gradually increases, creating a dynamic visual

Struggling to replicate a feature on a website where images gain opacity as you scroll down? Check out this site for reference: . While my current code somewhat achieves this effect, I'm having trouble figuring out how to apply a darker opacity gradua ...

The information being sent from Angular is not being successfully transmitted to the XAM

Here is my Angular service post method: getUserDetails(username , password) { alert(password); return this.http.post<myData>("http://localhost/test/api/auth.php", { username, password }); } This is the structure of my PHP file: <?php ...

Modifying shapes and figures in three-dimensional Javascript

I am currently struggling to transform a cube into a sphere in Three.js either after a specific time interval or upon an event click. I have attempted changing the geometry property from BoxGeometry to SphereGeometry with no success. Despite trying some po ...

Having difficulty validating the field accurately with Angular.js

In order to validate the input field in accordance with the user's needs using AngularJS, I have shared my code below: <div ng-class="{ 'myError': billdata.longitude.$touched && billdata.longitude.$invalid }"> <input type ...

Is there a way to maintain formdata between components in Angular?

With only the tools of @Input, @Output, routing, and activatedRoute at my disposal, I set out to create a dynamic application. In this project, there are two crucial components: addbook and showbook. The addbook component features a form with a submit bu ...

iteration using underscores in JavaScript

I am currently working on creating an object using underscore and backbone. I have an array of objects, each containing a nested object with different sets of data. Within the array, data[0] holds the name of a location while data[2] contains the coordina ...

Observable Knockout Dependency

I found an interesting example on the KnockoutJS site () and I want to implement something similar. My goal is to check if certain values are available on the client side when a category is selected. If they are not, then I need to fetch them from the ser ...

How can I extract the width of an uploaded image and verify it using JavaScript?

Is it possible to retrieve the image width through upload using PHP and then validate it in JavaScript? $_FILES['image'] If the image size is not equal to 560px, can we return false and display an alert message using JavaScript? Also, I am won ...

The res.download() function is not functioning properly when called from within a function, yet it works perfectly when directly called through the API in a browser

I have a button that, when clicked, triggers the downloadFile function which contacts the backend to download a file. async downloadFile(name) { await this.$axios.$get(process.env.API_LINK + '/api/files/' + name) }, app.get('/api/files/ ...

Setting an Element's attribute is only visible in the console

Just dipping my toes into the world of Web Development. While playing around with some JavaScript within HTML, I decided to try updating the content of an element. Upon running the code below, "Updated Content" appears in the console as intended. However, ...

What could be causing my issue with the if-else condition not functioning properly?

Why does the code only work for adding and removing styles in Part (else), but not returning the class when clicked again? var navDropDown = document.querySelectorAll('.menu-item-has-children > a'); for (let i = 0; i < navDropDown.length; i ...

Is it possible to execute node.js code within a Java script environment?

I have a javascript code that functions as a discord bot. Typically, to run this bot, I would open the command prompt in the js path and enter node {file_name}.js. Now, let's say I have another javascript code that I want to execute on button click an ...

Having trouble displaying API values in b-form-select component in Vue.js?

I am using an API to fetch users data and I want to bind these users to a b-form-select component in Bootstrap Vue. However, after making the request, I only see "null" in the b-form-select. Here is my request: getAllUsers() { axios.get(&a ...

Using React Refs to Trigger the video.play() Method - A Step-by-Step Guide

Is there a way to use a ref in order to trigger video.play()? Currently encountering an error: preview.bundle.js:261916 Uncaught TypeError: _this2.videoRef.play is not a function Take a look at my component: import React from 'react'; import s ...

The periodLookup array does not have a defined value for periodStr. Why is this error being caught?

Here is a method that I am working with: set_period_help_text: function(periodInput){ var metric = MonitorMetric.getSelectedMetric(); var periodStr = $('select[name=metric_period]').val(); var datapoints = Number(periodIn ...

Modifying SASS variable values based on the presence of specific text in the page URL

How can I utilize the same SASS file for two different websites with similar functionality but different color schemes? My goal is to dynamically change the color based on the URL of the page. However, I am facing challenges in extracting the page URL from ...

The TypeError encountered when using vue.js push arises from attempting to access the 'name' property of an undefined value

Here is a code snippet I am working with: new Vue({ el: '#core', data: { checkedThemes: [] ... } }) Afterwards, I have the following code: mounted() { ... var theme = parseInt(parameters['theme&apo ...

Leveraging geoPosition.js in conjunction with colobox

How can I create a colorbox link that prompts the user for permission to access their location, and if granted, displays a map with directions from their current location? I've managed to get it partially working, but there's an issue when the us ...