Hide objects within shape

Hide objects within shape

sean
Advocate Advocate
1,805 Views
7 Replies
Message 1 of 8

Hide objects within shape

sean
Advocate
Advocate

Hi all

Probably a stupid question.

 

I'm working on a scene with lots of lights.  Different lights are needed for different shots.

 

To try to speed up render time (out of curiosity, how much do lights affect render times?) I was thinking it might be good to have a script where you can put objects (lights) in a list..... assign a detector object, for example, a circle.

 

Similar to what Forest Pack can do..... but not FP.

 

Anything  outside the circle is hidden, saving the task of manually hiding stuff.

 

Anyone know if this would be possible?  Or hopefully anything like it that already exists.

 

Thanks

0 Likes
1,806 Views
7 Replies
Replies (7)
Message 2 of 8

leeminardi
Mentor
Mentor

The following script will hide all selected light objects that are at a distance greater than a specified distance from a point object named "PointEx".  PointEx should be selected along with all the other objects to be evaluated by the script.

 

 

-- Hides selected light objects that are at a distance greater
-- than a user specified value from the point object named "PointEx".
-- 
s = getKBValue prompt:"Enter distance to hide lights."
for i in selection do 
(
	pt = $PointEx.position	
	d = length(i.position - pt)
	if (superClassOf i )  == light and d > s then hide i
)
lee.minardi
Message 3 of 8

10DSpace
Advisor
Advisor

@sean 

 

Not a stupid question(s) by any means.  But strictly speaking, not exactly answerable as phrased, "how much do lights affect render times?", since the answer would depend on many scene factors (e.g,  the number of lights, the number and type of lights, the renderer,  number and size of materials maps (1k, 2K, 4K, 8K?) in the scenes, and (I think, but not sure) particularly with reflective surfaces, etc.  ..

 

But for the sake of discussion, let's say that the number of lights do affect render time to some extent in any scene and that it would be desirable to be able to selectively turn them on and off for different camera views/shots in a scene.  I think that is one of the prime use cases for State Sets in Max.  See link to some tutorials and docs if you are not familiar with State Sets.

 

https://www.google.com/search?q=3ds+max+state+sets&oq=3ds+max+state+sets+&aqs=chrome..69i57j0l7.2283...

 

It is some work to set up, but I have used it effectively for similar purposes in some scenes.   

 

The problem with the Circle (or Sphere or Camera View) approach (hiding lights within a specified area of a scene) is that lights whose position that fall outside of any volume you specify can still be affecting the geometry within the view.   Obviously depends on the scene, because you may have a set up with different rooms in a house for example with completely different lights, in which case the volume approach might be fine when there is no bleed in from neighboring lights.  But in other scenes, more distant lights can still influence the view, so no guarantee the approach would work.  I that case you will have to decide which lights are relevant for a given shot.  So I think this is a case where State Sets would be your best option in Max.   

0 Likes
Message 4 of 8

10DSpace
Advisor
Advisor

@leeminardi 

 

That's a pretty handy script for circumstances where the radius approach is all you need.   I also never knew you could get user input so easily via prompt in Listener (vs scripting a dialog box).  Thanks for posting.

0 Likes
Message 5 of 8

sean
Advocate
Advocate

Thanks both for the great replies. 

 

@10DSpace  I'll definitely have a look at state sets for a future project.  The one I'm working on at the moment doesn't have much time left so I don't even have time to look into it at the moment.

 

Thanks for the script @leeminardi   .  I don't know anything about max script but I assume it'd be ok to have $PointEx1, $PointEx2, or a more scene specific name in the initial variable?  Maybe a camera name.

 

We use Corona. Would == light still work or does it need to be Corona specific?

 

We use batchcam and you can use custom pre-render scripts for each camera.  If I get around to getting this to work it'd mean a point object can be in the same position of each camera and un-needed lights can then be turned off.

 

---------------

 

Hmmmmmm, but thinking now, on the lines with what @10DSpace  said, if I set the radius to be a certain value I can imagine lights I need around the site (in the background) will be turned off. Hmmmmmm

 

I'll test things.

 

Thanks again

0 Likes
Message 6 of 8

leeminardi
Mentor
Mentor

Thanks @10DSpace for the compliment. I have very limited experience with Maxscripts and still struggle with syntax and object references.  Thanks to google for making me look like I know what I am doing.

lee.minardi
0 Likes
Message 7 of 8

leeminardi
Mentor
Mentor

@sean   I am not familiar with Corona so I cannot help you there.

 

Below is a modified version of my earlier script.  It prompts you for a distance and the name of the reference object which could be a camera.

-- Hides selected light objects that are at a distance greater
-- than a user specified value from the specified object.
-- lrm 9/30/2020 
s = getKBValue prompt:"Enter distance to hide lights."
n = getKBLine prompt:"Enter name of reference object."
for i in selection do 
(
	pt = execute ("$'" + n )
	d = length(i.position - pt.position)
	if (superClassOf i )  == light and d > s then hide i
)
lee.minardi
0 Likes
Message 8 of 8

10DSpace
Advisor
Advisor

@sean 

 

We use Corona. Would == light still work or does it need to be Corona specific?

 

To find out if @leeminardi 's script will work with your Corona Lights, just select the Corona light and type:

 

superClassOf $

 

in the Max Listener Window and what is returned will be the way Corona lights need to be called.  For Arnold and Vray lights,  it returns "light" so, I am guessing (I also do not have Corona) it will also be "light" for Corona and Lee's script will work.  If it's something different, you can make a copy of the script and adjust it accordingly with the Corona superClassOf return type. 

0 Likes