Loading on click and then show

when i click on any texture the mesh gets dissappear and after some time the texture gets apperd, so i want to show that the loading animation or any solution so that the texture mesh doe not gets dissapper
https://playground.babylonjs.com/#SI13I2#25 this is my pg can any one help me @Evgeni_Popov @Siva_s @mawa @RaananW

Any texture has an observable that allows you to know when it was loaded.

Texture | Babylon.js Documentation (babylonjs.com)

So, depending on your loading screen, you can show it when creating the texture, and hide it when the texture was loaded.

A simpler solution would be to define both onLoad and onError callbacks in the constructor of the texture:

Texture | Babylon.js Documentation (babylonjs.com)

This way your app can react correctly to every state of the texture loading procedure.

1 Like

hi i tried to implement onload funtion but it did not work and when i press the button to change the texture the model gets dissappear fro some time and then the model gets apper.
pg https://playground.babylonjs.com/#SI13I2#45

I’m afraid not (sry). I hope you won’t hate me for constantly saying you chose the wrong method or approach.
What you want to do here is load all of your materials and texture at first so they will be ready when you call’em. If you load them only on button click, well… they will start loading only on button click. Obvious, isn’t it?
The onload function will work fine with your case and after all, you don’t have such a long list of materials and textures that you cannot load them all in scene.
Basically, what you will want to do is create a separate script for all materials and textures.
You will load this external script in your scene and use the onload function to perform the next steps (the steps requiring these materials and texture ONLY AFTER everything is loaded and ready).
You should really start to make a bit of ‘order’ in your structure before implementing new things.
As per my last posts, use comprehensive names for each (not conflicting with BJS naming convention).
Re-order your script:
-Set-up scene with ground, camera and light
-Define or import materials
-Import objects
-Transform objects
-Create Animation functions (or import animation script)
-Create advancedTexture
-Create controls
-Create Particles system
-Create Particles
-Create Post-process
-Declare scene init and specials (for dev or prod)
-Render scene

Some in this order can be changed depending on scenario but clearly your project at this time does not follow ANY known or recommendable structure.

Don’t get me wrong. I understand that this is all hard to learn at first and I’m happy to help (we all are) but in the end, you will have to make some effort to try learn things (like we all did) because simply copying the code of others will not bring you any further. Put your project on the side for a minute, take even just 1 hour a day to investigate the doc, watch a couple of videos and test in the PG. Believe me, if you do that in 6 months you will already have learned a lot. And you will be happy with it and really start enjoying BJS. Believe me :smiley:

1 Like

yes i know that but can you plz give me the advice what function should i use so that the mode does not get disapper while the texture is being selected.

I already told you. The material and texture needs to be loaded BEFORE the click. Best would be to have them loaded at scene ready. Best for handling, would be to have them in a separate script and make sure script is loaded before any interaction. All I can do more, is to give you the link or the code to do this

1 Like