Referencing Lights Imported From Blender

Recommended Posts

How would I reference a light imported from Blender? I'm appending a scene with a directional light (sun) as follows:

BABYLON.SceneLoader.Append("", "museumScene.babylon", scene);

Now, if I add a "fire when fully imported" function to return the array of lights in the scene, I see my sun in the console just as I'd expect:

BABYLON.SceneLoader.Append("", "museumScene.babylon", scene, console.log(scene.lights));

However, if I try to reference the sun in the normal way, I only get null:

BABYLON.SceneLoader.Append("", "museumScene.babylon", scene, console.log(scene.getLightByName("sun")));


Share this post

Link to post
Share on other sites

SpaceToast!  heh.  What a great name. 

I wonder what a scene.render() BEFORE the console.log... would do.

I wonder what scene lights could be found in... scene.executeWhenReady(function() { here } );

Just a couple of things to try.  Probably nothing useful, though.  :)

Share this post

Link to post
Share on other sites

Your intuition was right, Wingnut. Not a Babylon problem. It was one of those Javascript issues I can never seem to keep straight:

BABYLON.SceneLoader.Append("", "museumScene.babylon", scene, function() {console.log(scene.getLightByName("sun"));});

...creates a find-the-sun function that will be called when the loader finishes. This works!

BABYLON.SceneLoader.Append("", "museumScene.babylon", scene, console.log(scene.getLightByName("sun")));

...fires console.log() immediately when Append() runs, rather than waiting for the loader to finish. Hence, so sun!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.