sociofob Posted April 16, 2016 Share Posted April 16, 2016 Hi,I have hard times with asynchronous mesh loading. I need to apply textures to meshes right after meshes are ready. I'm importing in this way: var loader = new BABYLON.AssetsManager(scene); someLoader = loader.addMeshTask("roulette", "", "", "rouletteTable.obj"); anotherLoader =loader.addMeshTask("chip", "", "", "blackChip.obj"); someLoader.onSuccess = function (t) { t.loadedMeshes.forEach(function (m) { tableMeshArr.push(m); }); tableMeshArr[0].material = materialWheel; tableMeshArr[1].material = materialRoulette; tableMeshArr[2].material = materialBlack; }; anotherLoader.onSuccess = function (t) { t.loadedMeshes.forEach(function (m) { chip=m; chip.material=materialChips; }); }; loader.onFinish = applyObjTextures; loader.load(); var applyObjTextures = function () { tableMeshArr[0].material = materialWheel; tableMeshArr[1].material = materialRoulette; tableMeshArr[2].material = materialBlack; chip.material = materialChips; }; But it applies only to tableMeshArr[0] mesh. onFinish Callback works right after finishing importing first mesh, but I need a callback when all meshes are loaded. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 16, 2016 Share Posted April 16, 2016 I see no obvious error. Can you reproduce on the playground or share a link to your demo? Quote Link to comment Share on other sites More sharing options...
sociofob Posted April 19, 2016 Author Share Posted April 19, 2016 I supposed, the problem is in applying texture to mesh before texture is loaed. Obviously the solution here is to wait for loading, checking texture.isReady() time by time until it happens, but, it doesn't work in my case:( this.applyMaterials=function(){ if(wheelTexture.isReady&&rouletteTexture.isReady){ blackChipMesh.material=materialChips; redChipMesh.material=materialChips; blueChipMesh.material=materialChips; greenChipMesh.material=materialChips; whiteChipMesh.material=materialChips; plane.material = materialCarpet; tableMeshes[0].material = materialWheel; tableMeshes[1].material = materialRoulette; tableMeshes[2].material = materialBlack; } else { setTimeout (applyMaterials, 1000); } } I call this function onAssetsManager's onFinish callback var meshLoader = new BABYLON.AssetsManager(scene); //... meshLoader.onFinish = onMeshLoadingFinish; meshLoader.load(); But, I suspect this callback this callback dont work properly. Also, I have some error message in console, so that can be connected. I get this error although meshes are imported. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 19, 2016 Share Posted April 19, 2016 Can you reproduce on the playground or share a link to your demo? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.