Scene Image load complete

jtanz
Posts: 28
Joined: Mon Mar 27, 2017 11:24 pm

Scene Image load complete

Postby jtanz » Sun Apr 30, 2017 1:41 pm

Is there any functionality that lets me know when the image is done loading on a scene? I tried story.onSceneLoadComplete but the load completes before the image gets displayed on the screen. If I have high res images, I would like to display a loading bar animation while the image is loading, currently it either displays the old scene image or a black screen until the new scene's image fully loads.

User avatar
aberthet
ForgeJS Team
Posts: 16
Joined: Tue Dec 13, 2016 2:53 pm

Re: Scene Image load complete

Postby aberthet » Tue May 02, 2017 7:32 am

You have renderer.media.onLoadComplete (see here) that can maybe be what you're searching for. Use a addOnce on this event, everytime you have a change in the scene (story.onSceneLoadStart).

jtanz
Posts: 28
Joined: Mon Mar 27, 2017 11:24 pm

Re: Scene Image load complete

Postby jtanz » Wed May 03, 2017 1:50 am

Here is what I tried:

  1. forgeViewer.onReady.addOnce(function () {
  2.  
  3.     forgeViewer.story.onSceneLoadStart.add(function (event) {
  4.       var scene = FORGE.UID.get(event.data.uid);
  5.      
  6.       scene.media // is undefined
  7.       scene.config.media // is forge media object
  8.       scene.config.media.onLoadComplete // is undefined
  9.      
  10.       scene.config.media.onLoadComplete.addOnce(function () {
  11.         console.log('media.onLoadComplete!');
  12.       });
  13.      
  14.     });
  15. });



Am I correct to use the scene.config.media?

User avatar
rroux
ForgeJS Team
Posts: 120
Joined: Wed Oct 26, 2016 12:19 pm

Re: Scene Image load complete

Postby rroux » Wed May 03, 2017 9:28 am

Hi jtanz,

This code works with the ForgeJS 0.9.2 version

  1. var viewer = new FORGE.Viewer("container", "config.json");
  2.  
  3.         viewer.onReady.addOnce(function ()
  4.         {
  5.             viewer.story.onSceneLoadStart.add(function (event)
  6.             {
  7.                 var scene = FORGE.UID.get(event.data.sceneUid);
  8.  
  9.                 scene.media.onLoadComplete.addOnce(function ()
  10.                 {
  11.                     console.log('media.onLoadComplete!');
  12.                 });
  13.             });
  14.         });


Note that the event.data.uid is now event.data.sceneUid
You can also get the current scene reference just with viewer.story.scene

Am I correct to use the scene.config.media?


No, config objects are just objects containing strings, numbers and booleans. You will never find an EventDispatcher on this kind of object :)

Hope this helps!
- Raphaël

jtanz
Posts: 28
Joined: Mon Mar 27, 2017 11:24 pm

Re: Scene Image load complete

Postby jtanz » Wed May 03, 2017 2:03 pm

Ok, thanks! I will get the latest version of the library and test it out.
Edit - Upgrading from 0.9.1 to 0.9.2 fixed it.

Who is online

Users browsing this forum: No registered users and 2 guests