Update the PG of the Documentation DEMOS for Sceneloader ImportMesh, Append

In the import category of PGs and in the PG examples of the documentation, all the sceneloader is marking as Deprecated. I was wondering if it would not be useful to update with the new practice to be used rather than having official examples with noted functions not recommended. If they are not recommended, it should not be in the examples official.

For exemples this PGs :

And

I was looking for new practices quickly, and I only found Deprecated functions. So I told myself that it was necessary to submit the ideas of updating all the PG of the documentation.

Thank you

3 Likes

First of all, I would like to state that I do not have much knowledge on this subject, but since I also received a similar error, I would like to state that I actually agree with you. Because I also have difficulty finding information text after version changes or updates.

1 Like

I will ask the question differently. There is documentation for new imports ? being given that the current one are obsolete.

I can’t find anything anywhere on how to do this.
The doc Demo should be reviewed, or add PG for example for new practices to adopt.

obsolete :
BABYLON.SceneLoader.Append
obsolete :
BABYLON.SceneLoader.ImportMesh
obsolete :
BABYLON.SceneLoader.ImportMeshAsync
obsolete :
BABYLON.SceneLoader.LoadAssetContainer
obsolete :
BABYLON.SceneLoader.ImportAnimations
obsolete :
BABYLON.SceneLoader.AppendAsync

Everything in Sceneloader has become Deprecated. What should be used now to take into account new ways of doing things ? I did not understand and I can’t find any information on it, or an example.

All this documentation is obsolete :

I found that: (Is that how we should do it ?)

BABYLON.LoadAssetContainerAsync("scenes/skull.babylon", scene, {
        onProgress: e => {
        
        }
    }).then((result) => {
        result.addAllToScene();
        const mesh = result.meshes[0];
        camera.target = result.meshes[0];

    });

I still have a bit of trouble understanding everything. especially on the result.addAllToScene();
Does that mean that we can add several paths :

const paths = ["scenes/mesh1.babylon", "scenes/mesh2.babylon", "scenes/mesh3.babylon"]
BABYLON.LoadAssetContainerAsync(paths, scene, {

Something like that? I have never used assetcontainer since it exists.

All functions are flagged with their new version:

See the “Please use AppendAsync”

So for this PG: glTF Loader Demo | Babylon.js Playground

the solution is:
glTF Loader Demo | Babylon.js Playground

That being said, we need to make that doc page clearer and add a link to Loading Any File Type | Babylon.js Documentation

(cc @PatrickRyan)

Thank you @Deltakosh for clarification, but how do I replace SceneLoader.ImportMeshAsync ?

Here is my use case. sceneloader.Importmeshasync is super simple: you load a mesh, it appears in the scene.
I charge all the meshes one by one in a loop using : for (const data of sceneData) SceneLoader.ImportMeshAsync

But with BABYLON.LoadAssetContainerAsync or BABYLON.AppendSceneAsync this does not work for my use case. Or I didn’t understand like doing it.

Here is what I do. I load my scene from a JSON file which contains the paths of models and metadata to rebuild it. :

async loadScene(projectName, levelName) {			
	try {
		const response = await $.ajax({
			url: "../Core/PHP/load_scene.php",
			method: "GET",
			data: {
				"project": projectName,
				"filePath": '../../_Projects/' + projectName + '/Data/scene_' + levelName + '.json'
			}
		});

		const sceneData = JSON.parse(response);
		if (utilities.isObjectEmpty(sceneData)) return;

		for (const data of sceneData) {
			const filePath = utilities.getPath(data.source);
			const fileName = utilities.getFile(data.source);

			const result = await BABYLON.SceneLoader.ImportMeshAsync("", filePath, fileName, this.scene);

			const mesh = result.meshes[0];
			
			//...	Other code ...		
		}
	} catch (error) {
		console.error("Error when loading the scene : ", error);
	}
}

LoadAssetContainerAsync loads all the meshes, but does not load the meshes one by one and AppendSceneAsync does the same thing A can ready. Why is there not BABYLON.ImportMeshAsync Isn’t it also available to load a model that is added to the scene as simply as possible?

Sorry for my misunderstanding.

1 Like

Simply with BABYLON.ImportMeshAsync() :slight_smile:

That’s what I’m looking for it, but does not seem to exist : BABYLON.ImportMeshAsync()

I tried to do like that. But it generates an error:

RuntimeError: Unable to load from …/GameClient/Data/Meshes/Props/Barel.babylon: OK

for (const data of sceneData) {
    const result = await BABYLON.LoadAssetContainerAsync(data.source, this.scene);	        
    result.addToScene();
    const mesh = result.meshes[0];
}

The path of the file exists, but it does not seem to want this load.
If I do it with:

for (const data of sceneData) {
    const filePath = utilities.getPath(data.source);
    const fileName = utilities.getFile(data.source);
    const result = await BABYLON.SceneLoader.ImportMeshAsync("", filePath, fileName, this.scene);
    const mesh = result.meshes[0];
}

There it works.

And I can’t find BABYLON.ImportMeshAsync() Neither in the doc nor in the PG.

Also this unique example PG with LoadassetContaineSync is in typescript and quite complicated to understand.

As far as I understand, addAllToScene allows you to add all entities from your imported scene. On the other hand, addToScene allows you to specify a filter function (predicate) to select only the specific entities that satisfy your predicate. Take a look at the following example, it adds all entities except the robot’s body (entity.name !== 'Box'):

Can this playground be useful? Basically is the same playground you quoted but with a single mesh (skull) imported with the asset container.


@Deltakosh it seems that ImportMeshAsync isn’t exported from sceneLoader.ts:

Unlike other exported functions, it doesn’t belong to a PascalCase wrapper. Could it be missing a wrapper and the corresponding export?

1 Like

cc @RaananW or @ryantrem who I think worked on that PascalCase story

1 Like

Thank you @SimoneDev
I think I will wait for the availability of importMeshAsync which would be more appropriate for my case. Because I load all the models one by one in a loop and an assetContainer or appendScene does not work for my use case.

1 Like

Can you load your scene/mesh (…/GameClient/Data/Meshes/Props/Barel.babylon) in the playground without loop? Or do you have some errors? For instance swapping the resource url here:

On my project I have mistakes. And with assetconainer we cannot recover the mesh with const mesh = result.meshes[0];

Here is what I had tried:

async loadScene(projectName, levelName) {			
	try {
		const response = await $.ajax({
			url: "../Core/PHP/load_scene.php",
			method: "GET",
			data: {
				"project": projectName,
				"filePath": '../../_Projects/' + projectName + '/Data/scene_' + levelName + '.json'
			}
		});

		const sceneData = JSON.parse(response);
		if (utilities.isObjectEmpty(sceneData)) return;

		for (const data of sceneData) {
			const filePath = utilities.getPath(data.source);
			const fileName = utilities.getFile(data.source);

			//const result = await BABYLON.SceneLoader.ImportMeshAsync("", filePath, fileName, this.scene);

                const result = await BABYLON.LoadAssetContainerAsync(data.source, this.scene);	        
        		result.addToScene();

			const mesh = result.meshes[0];
			
			//...	Other code ...		
		}
	} catch (error) {
		console.error("Error when loading the scene : ", error);
	}
}

And I receive this error in the console:

Runtimeerror: Unable to load from …/gameclient/data/meshes/props/barel.babylon: OK

Cela fonctionne si j’utilise :
const result = await BABYLON.SceneLoader.ImportMeshAsync("", filePath, fileName, this.scene);

So I think BABYLON.importMeshAsync would better if he could be there.

I cannot create a PG with my model, because I develop my project locally. But the model works properly using BABYLON.SceneLoader.xxx

1 Like

Thank you for sharing! From the snippet, I can’t figure out the reason why and the only difference i see is the usage of filePath and fileName rather than data.source, so i thought that:

const result = await BABYLON.LoadAssetContainerAsync(filePath+fileName, this.scene);	        

would work.

Anyway, it intrigued me because, most of the time, I like to load assets from asset container, do some work (transformations, rotations, etc.) and only at the end show them. This helps me avoid glitches that might occur with ImportMeshAsync that shows the asset as soon is loaded. But… the beauty of Babylon.js is that it allows you to do so many things in so many different ways, so keep pushing! :mechanical_arm:

When we switched to the module level functions, I tried to update all the docs and Playground examples, but I may have missed some. I will take a look through this thread and make sure we get the other ones updated.

Also when we switched, we didn’t expose an ImportMeshAsync module level function because the thought was that LoadAssetContainerAsync could do the same thing plus more, so it was redundant to add ImportMeshAsync. That said, we’ve heard feedback on this a few times now, so I will go ahead and add this one into the mix as well.

For the issue mentioned above with LoadAssetContainerAsync, I will take a look at that as well this week and circle back!

4 Likes

Thank you @ryantrem to reconsider the ImportMeshAsync and to revise the LoadAssetContainerAsync.

@SimoneDev In fact data.Source in my JSON file, is the full path of the model.
And filePath+fileName is the same thing but by separating the file and the for the importMesh with :

const filePath = utilities.getPath(data.source);
const fileName = utilities.getFile(data.source);

So it comes back to the same if I do:

const result = await BABYLON.LoadAssetContainerAsync(filePath+fileName, this.scene);
//Or
const result = await BABYLON.LoadAssetContainerAsync(data.source, this.scene);

It generates the same error. But maybe this error comes from after. That is to say when I do: Const mesh = result.meshes [0]; I do not know how a assetContainer works, but from what you describe to load the models at the end and to do all the transformation before is interesting too.

@Dad72 do you have a Playground for the LoadAssetContainerAsync issue you are having?

@ryantrem No I have no playground. I develop my project locally.
But I will try to see if I can’t create one otherwise. I would try to do that tomorrow in the day hoping to reproduce the problem.

1 Like

I have a PR out to add ImportMeshAsync as a module level function (and update doc comments to further help lead folks to the module level functions). That said, from everything you are describing, LoadAssetConatinerAsync should work just fine, so I’m definitely curious to see a Playground with a repro!

Also a second PR to update the docs and point to updated PGs for the ones you found that use the legacy SceneLoader.

3 Likes

@ryantrem I tried to make a PG before going to bed. I can’t reproduce the problem. But I see another.

If you look at this PG you will see that with BABYLON.LoadAssetContainerAsync, the brightness increases sharply. (The meshes are much white)

Make a comment on line 47 and you will see the difference using BABYLON.SceneLoader.ImportMeshAsyn then BABYLON.LoadAssetContainerAsync

I would continue tomorrow to try to understand what to create a problem on my project.