ScriptSpot

Script

Switch light by volume

By grabjacket · 2010-09-21

Version
3
Version requirement
written in 2010. also tested in 2012 Probably compatible with 9
Date updated
2011-10-08
Votes
11
Download
Download
Description

This script switches lights on and off whether they're inside or outside a mesh-volume. The main method is taken from cgtalk


You can also animate the lights



Use a volume to control the lights

Also see this article on my blog

Videos

Tags: volume select light

Comments (4)

grabjacket · 2010-09-24

Sure Anubis,

I've posted the file on my blog, but here's the link direclty.
If the file doesn't work, you can easily recreate the scene by creating an array of 10x10x10 point helpers and a large torusknot in the middle. Let me know what you find out!
Klaas

Anubis · 2010-09-23

Hey Klaas, nice script.
I wish to make some test with your example max scene, but I use Max 2009, so I'll glad if you can send me (at anubiss[at]abv[dot]bg) the scene saved in Max 2009 or export it to FBX. If you choose FBX, pleace be sure that the file format version is FBX200900 then export it.

Thanks in advance,
Anubis

grabjacket · 2010-09-22

Hey Insanto, I've tested it today. At first the method I used was waaay slower because of the repetitive adding and removing the normalmodifier. I've moved that part to a new location in the script, outside of the loop. Now my method (Matan Halberstadts actually) is a bit faster.
average of ten iterations running on a bunch of points and a single volume
10 points check
isPointInVol: 20ms
fn_isObjInsideVolume: 28ms
100 point check
isPointInVol: 199ms
fn_isObjInsideVolume: 144ms
500 point check
isPointInVol: 934ms
fn_isObjInsideVolume: 558ms

So my method is a bit faster. Also check out my blog for the testmethod and testscene.

Graph · 2010-09-22

thats quite a nice one, would you mind testing if your method of determining the volIntersect is faster than mine?


		fn isPointInVol obj pos = --checks if supplied position is inside supplied mesh object
		(
			if superclassOf obj == geometryClass do ;
			(
				local tMesh = obj.mesh; local nVerts=tMesh.numverts; local isInVol = true ;
				for v = 1 to nVerts while isInVol do if asin (dot (getNormal tMesh v) (normalize(((getVert tMesh v)*obj.transform) - pos))) <= 0.0 do isInVol = false ;
				tMesh = nVerts = vPos = undefined ;
				return isInVol ;
			)
		)--END isPointInVol FN