Search the Community
Showing results for tags 'multi-threading'.
-
Let me start by stating that I have thousands of meshes to import into a scene. Since the following loop will not work because i is incremented before the callback function of ImportMesh is complete for (var i:=0; i< max;i++) { BABYLON.SceneLoader.ImportMesh("", "products/", productBabylonName, scene, function (newMeshes) {}); newMeshes.position = new BABYLON.Vector3(x,y,z) } I solved the problem by creating a recursive loop. Here is my code productLocationData (JSON format) & productCount are retrieved from database using a AJAX-PHP-MySQL call var Pindex=0; populateRack ( productLocationData , productCount,Pindex ); var populateRack = function(productLocationData,productCount,Pindex) { var popRackProdPositionX = parseFloat(productLocationData.products[Pindex].positionX); var popRackProdPositionY = parseFloat(productLocationData.products[Pindex].positionY); var popRackProdPositionZ = parseFloat(productLocationData.products[Pindex].positionZ); var productBabylonName = productLocationData.products[Pindex].productBabylonName; BABYLON.SceneLoader.ImportMesh("", "productshr/", productBabylonName, scene, function (newMeshes) { newMeshes[0].position = new BABYLON.Vector3(popRackProdPositionX,popRackProdPositionY,popRackProdPositionZ); });//end import Pindex +=1; if (Pindex < productCount) { populateRack(productLocationData,productCount,Pindex); } } Everything works fine. However, if there is a simpler way please advise. HOWEVER my MAIN question is the following. Can I run many instances of the above code in parallel ? Reason being of course to have everything load faster. I know that javascript is a sinle-threaded language. Could HTML5 web workers be of help here? Or any other plug-in such as parallel.js ? Has anybody applied parallel processing to BABYLON.SceneLoader.ImportMesh. I am aware that Web Workers has been applied to collisions. Does anybody have an example?