Sending custom objects to web workers can lead to losing prototype information

Dealing with exporting data from a three.js mesh to a string inside a web worker has been challenging for me. The issue arises when prototype information is lost, not due to three.js itself but because of the web workers. Essentially, my goal is to send objects to the web worker and utilize them in an imported script.

This snippet shows my web worker code:

importScripts('../editor/three.js', '../exporter.js');

onmessage = function(event) {
  postMessage(event.data);
  export(event.data);
 };

The event.data object contains faces and vertices, and postMessage successfully sends the correct information. For example, the normal vector retains its clone() function.

The problem surfaces when I attempt to access the data in the export() function. While the values are accurate, all prototype information is lost. This means that the normal vector has properties x, y, z, but no longer recognizes the clone() function.

The export() function is defined in exporter.js with the definitions of three.js objects residing in three.js file.

Any suggestions or ideas on how to solve this?

Thank you.

Answer №1

This may seem like a silly question, but it's worth noting that according to the specifications for web workers, only strings are allowed to be passed.

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

Mockgoose encountered an error during shutdown: ENOTCONN

It's making me lose my mind. I'm currently executing some unit tests with the following configuration import mongoose from "mongoose"; import mockgoose from "mockgoose"; import chai from "chai"; import chaiAsPromised from "chai-as-promised"; i ...

Retrieve data from an external source and display it on my website

Is there a way to extract information from the IEEExplore page using Jquery or Javascript? Can the data be retrieved in JSON format for display on another webpage? I am thinking of using something like this: $.get(url,function( data ) { alert( "Dat ...

What is the best way to eliminate the initial key from a JSON object

How can I remove the first index in a JSON object? JSON: {"data":[{"label":"Data","data":1},{"label":"Website","data":1}]} I need: [{"label":"Data","data":1},{"label":"Website","data":1}] When I try to delete .data, it outputs object{} JavaScript c ...

When using NextJS <Link, mobile users may need to tap twice to navigate

Whenever I use the NextJS <Link tag on my mobile device, I notice that I have to double-tap for the link to actually route to the desired page. Take a look at the code snippet below: <Link href="/methodology" passHref={true} ...

Unexpected results from the match() function

Attempting to utilize the RegExp feature in Javascript (specifically with the match function) to locate instances of a sentence and a specific word within that sentence embedded in the HTML body. Provided is some pseudo-code for reference: <!DOCTYPE ...

Show the HTML code within the form with the identifier html-editor-form

I have four different sections which are displayed when the corresponding icon is clicked. The area labeled as visual-editor contains multiple HTML values. I am looking to showcase all the HTML values within the visual-editor class under the html-editor ...

JQuery Ajax call fails to retrieve any information

I have been experimenting with JQuery Ajax methods. I created a basic Ajax request to retrieve specific 'tagged' photos from Flickr. Here is the code snippet I am using: function initiateSearch() { $(function() { var tagValue ...

Retrieve information from a JSON file and dynamically showcase it within a REACT component

Hey there! I'm a newbie in the world of programming and currently working on creating a carousel using Bootstrap and React. My aim is to make the Carousel images dynamic by fetching data from a local .json file. However, my current implementation seem ...

Is there a way to transfer an image from background.js to background.html?

I'm in the process of creating a chrome extension that involves making an API call every hour to retrieve an image, which I then want to save in chrome.storage.local. However, the size of the image is quite large, so I'm resizing it using a canv ...

Ways to stop the browser from ending the connection?

I'm working on a project using node/express/react, built with create-react-app. I'm facing an issue where the browser automatically closes post requests that take longer than 2 minutes. Specifically, in Chrome, the requests are being closed at e ...

Grails: Javascript function for updating the image source is unresponsive

I have a situation where I need to change the src of an img based on a certain condition. The condition is returning true as expected, as confirmed by an alert() that I added previously. However, the function responsible for changing the src of the img and ...

"Obtaining table row values by clicking a button in Angularjs - a step-by-step guide

I am seeking guidance on extracting the table row values of the selected row in the provided Plunkr. When a row is selected using the checkbox in the table and the update button is clicked, I require the row ID, name, and values. You can access the Plunk ...

When I utilize $router.push() to navigate to a different page, the back button will take me back to the previous page

Within my Vue project, there is an HTML page that I am working on. Here is the link to the page: https://i.sstatic.net/cbtqM.png Whenever I click on the "+"" button, it redirects me to this specific page: https://i.sstatic.net/0rmMD.png This page funct ...

Matching words with their meanings - exploring storage possibilities

I want to create a system to store vocabulary words and their translations in an organized manner... One idea I had was to use an associative array where each object represents a word and its translation. var vocab = []; vocab.push({"chinese" : "Nǐ", "e ...

Troubleshooting NodeJS with Socket.IO 1.0: Identifying Memory Leaks Beyond the Heap

We have encountered an issue while trying to deploy a small NodeJS app with Socket.IO. The problem arises when the total memory usage (rss) exceeds 2gb after approximately 2 hours, despite the heap size being within acceptable limits. To confirm that the ...

Having issues with setInterval function when restricting the number of MySQL rows

My simple chat application with setInterval is experiencing an issue when I try to limit the number of rows displayed from the database. Currently, the chat loads everything from if($q == "load") { and functions correctly. However, when I attempt ...

How can I prevent SoundCloud from playing in the background?

When utilizing the ajax page switching method along with the SoundCloud script, I'm encountering an issue. How can I ensure that the music stops playing when a user navigates away from the page containing the SoundCloud container? Any advice on what s ...

Retrieve an array object containing specific properties using axios

Currently, I am retrieving JSON data from an API call using axios and displaying it through Vue. This snippet shows the JSON Object logged in the console: 0: category_id: "categ1" item_name: "item1" price: 100 stock: 155 1: c ...

Utilizing Google Geochart for displaying multiple data values within the same country from JSON dataset

I am facing an issue where only the last row is being displayed in a Google Geochart for each country, despite trying to fetch data from my database via JSON. The problem is that only 'Supplier 2' is showing up, as highlighted below. I have gone ...

Apply express middleware to all routes except for those starting with /api/v1

Is it possible to define a catchall route like this? app.get(/^((?!\/api/v1\/).)*$/, (req, res) => { res.sendFile(path.join(__dirname, '../client/build', 'index.html'));}); ...