Jump to content

Lights, excluding and including meshes


gryff
 Share

Recommended Posts

I'm trying to get my head around the functionality that allows lights to only illuminate certain meshes - namely using  includedOnlyMeshes and excludedMeshes .

 

And I seem to have run into a problem which hopefully you can see with this playground example

 

Lights

 

The example has two spheres, sphere(centre screen) and sphere2 (right side). Down the script four lights are set up and there are some marked lines of code for "turning off" the red and green lights for the centre sphere.

 

The red light is "turned off" by using this line of code:

light0.includedOnlyMeshes = [sphere2];

which tells the red light to only illuminate the sphere2. Seems to work fine

 

I then try to turn off the green light on the centre sphere with this line of code:

light1.excludedMeshes = [sphere];

which tells the green light not to illuminate the centre sphere. It does not work

 

 

So is it my code  :unsure:  or has something changed in BJS with the addition of "includedOnlyMeshes"?

 

Any help appreciated before I pull out all my hair :o

 

cheers, gryff :)

 

Link to comment
Share on other sites

  • 1 month later...

Hi,

 

I would like use the ambient light only for specific mesh and his children,I understand that this is not possible because it only tested if the mesh given in parameter is in the list.

 

Is it possible to test with the method Node.isDescendantOf on the mesh ? I guess not because it would consume too.

 

Soulangel

Link to comment
Share on other sites

  • 2 years later...

Okay, so... assuming that I'm not the only one who didn't see an answer on this thread, here is what I found:

    light.excludedMeshes.push(mesh0);
    light.excludedMeshes.push(mesh1);

effectively removes meshes from the light source.  

http://www.babylonjs-playground.com/#1DLERH#1  I just made it so "sphere" only has the blue light with

    light0.excludedMeshes.push(sphere);

    light1.excludedMeshes.push(sphere);

 

ALSO, to use

    light.includedOnlyMeshes.push(sphere);

you first need to disable the light then enable it after... see the edit on my next comment. But this is what it looks like from the other direction:

http://www.babylonjs-playground.com/#1DLERH#2

Link to comment
Share on other sites

Oh, I just realized that 

light.includedOnlyMeshes.push(mesh3);

probably doesn't work because you probably have to clear the array first.

EDIT:   Clearing the array doesn't seem to change anything.  However disabling the light and then enabling it again after seems to work fine!  Like this:

    lightSaturn.setEnabled(false);
    lightSaturn.includedOnlyMeshes.push(saturn);
    lightSaturn.includedOnlyMeshes.push(rings);
    lightSaturn.setEnabled(true);

So, hopefully that's useful.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...