Issue with SceneLoader.Append

we have used SceneLoader.Append and loading the gltf with an url we need to set position to the object that has loaded we will be having multiple objects.for which we need to set positions…In sandbox, object is loading but need to set position to the object
By using SceneLoader.Append it is sticking to a paticular place how can we change the position of the object can you please provide the solution with an example @mawa or any one please help me out

Hi,

Maybe you could use SceneLoader.ImportMesh instead ?

The onSuccess callback has a “meshes” argument which is an array of the meshes you loaded, so you can update their positions here.

2 Likes

we need load gltf from url is it possible with SceneLoader.ImportMesh can please given me examples

Yes, you can load gltf by url via ImportMesh.

I made a PG example, where 3 gltf are loaded and set to different positions:

It would also be possible to set position on outer scope using Observables, that notifies if loaded:

Another way would be to use AssetsManager/AssetsContainer if you only load them once or instantiate:

1 Like

You can use append or import and then with the ‘async’ function, it doesn’t really make a difference.
The main point to understand is that before accessing and attempting to transform the mesh, you need to make sure it is loaded first.
The first way you can achieve this is by making the transform within your import function. It will read the function in order, starting by importing the meshes, next reading any transform.
The second way is by using a ‘promise’ with the ‘then’ condition. You promise the load of your mesh and once ready, you can set any transform you want following the ‘then’ condition.
Third, there’s also the ‘onReady’ runtime function. It checks when your (i.e. scene) is ready and applies any transformation only once the onReady state has been read.

thank you @SvenFrankson
tq all

While ImportMesh returns an array of meshes, it is pretty important to know that you can ask the scene to return any mesh by either its name or id. Not only that, scene can also get you a material, light, camera, and more with similar call to scene.getMeshByName().

The call can be put in the callback of Append(), or inside a scene.executeWhenReady(). For both of those, the mesh should exist by then. You cannot just call it after the append, since fetching the export file from the url is not a synchronous operation.

Think deciding between Append & ImportMesh might be best left to whether you are doing all meshes (Append) or just some (ImportMesh).