I am attempting to utilize dracoLoader from threeJS in a multi-threaded environment. To achieve this, I decided to use Webworker and IndexedDB. Although I have successfully obtained the correct Geometry in the web worker, I am facing an issue when passing the data to the main thread using IndexedDB. The transferred geometry is being transformed into a normal JS object instead of remaining as a ThreeJS Geometry. As a result, the geometry loses its functions and some essential information.
webworker.js
self.saveDrcToIndexedDB = function (drcfinal) {
var db;
var request = indexedDB.open("drcDB");
drcfinal.indexName = self.randomStr();
request.onupgradeneeded = function(event) {
console.log('successfully upgraded db');
db = event.target.result;
var objectStore = db.createObjectStore("drcfinal", { keyPath: "indexName"});
};
request.onsuccess = function(event) {
console.log('successfully opened db');
db = event.target.result;
var transaction = db.transaction(["drcfinal"], "readwrite");
var objectStore = transaction.objectStore("drcfinal");
objectStore.add(drcfinal).onsuccess = function(event) {
self.postMessage(drcfinal.indexName);
};
}
}
main.js
var worker = new Worker('webworker.js');
worker.addEventListener('message', function(e) {
indexedDB.open("drcDB").onsuccess = function(event) {
let db = event.target.result;
let objectStore = db.transaction(["drcfinal"]).objectStore("drcfinal");
objectStore.get(e.data).onsuccess = function(event) {
console.log(event.target.result);
};
}
}, false);
worker.postMessage(somedata);
Is it possible to transfer a correct geometry to the main thread? Are there alternative tools that could be used in place of IndexedDB? What about utilizing different multi-threading tools aside from Webworker?