Hide objects and lights outside of a box

Does anyone know how to write a script that will hide objects and v-ray lights that are completely not inside or touching a box? The script just needs to be a function. It would be best if it didn’t have an interface.

They reason why I need this, is I am rendering animations with v-ray, deadline, and RPManager and if I can hide the objects and lights I don’t need, per camera shot, it will substantially reduce my render times. Deadline has an option which will delete hidden objects, and in doing so, it reduces the size of the submitted files and reduces render time. I have been using layers and selection sets but they do not work well enough for what I need. Thank you for any help you can provide!

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
miauu's picture

.

The code below is from script, that I did not wrote. All credits goes to the author - Klaas Nienhuis, [email protected], www.klaasnienhuis.nl
Tested on max2014 with standard lights.
How to use it - select the box, that will be the volume object and execute the script. If it works, you can save it is macro script and assign hotkey or toolbar button.

(
	--	credits to Klaas Nienhuis, [email protected], www.klaasnienhuis.nl
	--	the function is from http://www.scriptspot.com/3ds-max/scripts/switch-light-by-volume
	function fn_isObjInsideVolume theObj theVolume=
	(
		/*
		fn_isObjInsideVolume
		handles the calculation if an object is within a specified mesh-volume
		expects the top modifier of the volume-object to be a normalmodifier
		*/
 
		local inside = false
		theVolume.modifiers[1].flip = true --this has to be a normalModifier
		local myHit = intersectRay theVolume (ray theObj.pos [0,0,1])
		if myHit == undefined then
		(
			inside = false
			)else 
			(
				theVolume.modifiers[1].flip = false
				local myHit2 = intersectRay theVolume (ray theObj.pos [0,0,1])
				if myHit2 == undefined OR (distance myHit.pos theObj.pos) < (distance myHit2.pos theObj.pos) then
			(
				inside = true
			)else
			(
				inside = false
			)
		)
		inside
	)
	--	select the volume object and execute the script
	objVolume = selection[1]
	addModifier objVolume (normalModifier flip:true)
	for o in objects where ( (o != objVolume) and (fn_isObjInsideVolume o objVolume ) == false ) do
		o.isHidden = true
)
mmaitland's picture

Thanks! Almost there..

Thank you very much Miauu and Klaas ! This is very close to what I want. I need to tweak the script a little so it will also include intersecting geometry. I have some objects that have pivot points which are outside the volume. If I can figure out how to modify this correctly I’ll post my results or if anyone already knows please post. Thanks!

miauu's picture

.

Send me([email protected]) a sample scene with all possible situatios(positions and intersections). Or post the link to the scene here.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.