Jump to content

Engine creates meshes, but doesn't update them.


kaitek666
 Share

Recommended Posts

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.

raider.png.c60dff594bcff60e1aee62f2897632c0.png

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:

raider2.png.5d25324da86d77e5d0f4baae7197b3a6.png

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:

raider3.png.c8b757c1f5c557a9e2c7a87919259867.png

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...