kaitek666 Posted April 4, 2017 Share Posted April 4, 2017 Hey! I created another topic lately, but my problem changed a lot. I have a rockraider.babylon model (included in attachments). I created it and it's being displayed. Everything's OK. class RockRaider { constructor(xpos,zpos) { var raider; this.ready = false; BABYLON.SceneLoader.ImportMesh("", "CanvasRR0/", "rockraider.babylon", scene, function (newMeshes){ console.log("Number of meshes... " + newMeshes.length); newMeshes.forEach(function(mesh){ mesh.scaling.x = mesh.scaling.y = mesh.scaling.z = 1.3; }); raider = newMeshes; }); setTimeout(() => { this.raider = raider; this.ready = true; }, 1000); } moveTo() { this.raider.forEach(function(mesh){ mesh.__tak = true; mesh.position.x = 10; }); } } (I'm sorry for no syntax. I cannot set it. Here's a pastebin version with highlighted syntax if you wish) Then, when I want to use function rockraider.moveTo(), via developer console, (which is supposed to place all meshes in x = 10), only a few of them are being moved. Left: Original meshes.Right: Translated meshes to x=0 My model has 9 meshes. Here's an image showing which meshes has been moved and which hasn't: This is a list of meshes taken from Blender. But hey, there's more! To debug, I gave each mesh a __tak variable and set it to true. I can see this value in every mesh of this model. Even if I use rockraider.raider[0].dispose(); and then rockraider.raider[1].dispose(); etc., The elements are actually being disposed. They get removed.But not all of them!! Even if some meshes don't even exist in console after disposing them, They still appear on screen. For example, when I type in in developer console: rockraider.raider.forEach(function(mesh){ mesh.dispose(); }); This is what I get: Some of the meshes disappeared, but the rest are still on the screen. How and why? Is this a bug? Is this fault of engine, or model? In attachments I included rockraider.babylon. I need explanations, ideas, etc. I'm using BJS v2.5 stable (latest) and Exporter for Blender v5.2.0. rockraider.babylon Quote Link to comment Share on other sites More sharing options...
davrous Posted April 4, 2017 Share Posted April 4, 2017 Hello, I don't repro on our PlayGround using your model: http://www.babylonjs-playground.com/#236AN2 (press s to scale and m to move). It must come from somewhere else in your code. Can you try to reproduce on our playground? Thanks, David Wingnut 1 Quote Link to comment Share on other sites More sharing options...
adam Posted April 4, 2017 Share Posted April 4, 2017 I used this http://www.typescriptlang.org/play/index.html to convert your code so that it would work in the PG. I made a couple of changes that might be helpful. http://www.babylonjs-playground.com/#236AN2#5 kaitek666, JohnK and Wingnut 3 Quote Link to comment Share on other sites More sharing options...
kaitek666 Posted April 4, 2017 Author Share Posted April 4, 2017 Found the solution. Thanks @adam for code sample, that helped me out as well. What was the problem? Scene loader sequence. Mid-loading of my model, engine was running a RenderLoop, causing half of model load, and the second half to load in.. a different way. I'm using this code temporary: setTimeout(function() { var scene = createScene(); setTimeout(function() { engine.runRenderLoop(function () { scene.render(); }); }, 1500); }, 2000); Which is really nasty! I need to fix execute sequence. Thanks a lot guys! Kajtek davrous 1 Quote Link to comment Share on other sites More sharing options...
brianzinn Posted April 4, 2017 Share Posted April 4, 2017 If you have something running async that you want to wait for - can you not pass in a function? I do this sometimes with animations: function createScene(onSceneLoadedAfterAnimation) { ... create scene here. this.scene.beginAnimation(target, 0, 30, false, 1, () => { onSceneLoadedAfterAnimation() } } Then you can call it like: createScene(() => { engine.runRenderLoop(() => { scene.render() }) }) I remember reading model loading have a completed event handler. I try to avoid setTimeouts when there are hooks to accomplish same. I think you can pass the function through to SceneLoader.ImportMesh success parameter. I should add that the animation here won't work, but you get the idea of passing a function on success running other code instead of a timeout. kaitek666 1 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.