PDA

View Full Version : intersectray and shadowing...


3rd Dimentia
06-19-2008, 04:43 AM
I need to do a test on verts of an editable poly to see if a light is reaching or is being shadowed by other geometry. I was thinking of creating a vector between the vert and the light and iterating thru all the visible objects in the scene to test in both directions, whether an intersectray hits the interated object. I've not used intersect ray before but for some reason I think it only works in one direction based on the normals of the object that I'm trying to send the ray to,(That might have been from bobo's advanced maxscript DVD or I might have got the wrong end of something. As it's a vague memory) Can anyone shed any light on this or even tell me that I'm thiking about it all wrong? Or is there a better way to test if a vert is being lit or shadowed by specific lights?

Also, while I'm here, does anyone know a good way to update an editable poly after vertex color changes? It doesn't want to seem to update.... I'm currently using converttopoly as a hack as update doesn't seem to want to work.

Thanks all,

Cg.

ZeBoxx2
06-19-2008, 11:45 AM
for some reason I think it only works in one direction based on the normals of the object that I'm trying to send the ray to
Correct, ergo:

test in both directions
good :)

Or is there a better way to test if a vert is being lit or shadowed by specific lights?
Can't say I know of a -better- way per se. IntersectRay, IntersectRayWorld (2008/AVG) and RayMeshGridIntersect (6) are it. Especially the last one is nice as it can go over scene objects -very- quickly and has built-in functionality to deal with the 'both directions' bit, as well as specifying the ray implicitly using two positions (no need to contruct a ray involving making the second position relative, etc.)


a good way to update an editable poly after vertex color changes?
Haven't the foggiest.. the following code seems to work just fine on an object converted to editable poly, without further code required.
polyop.setVertColor $ 0 #{1..10} (color 255 0 0)

pico75
06-20-2008, 09:41 AM
hi chris

im currently working on something very simmilar. i would like to get a visual feedback on vertical and horizontal surfaces (arch.building) hiting by the sun (daylight simulation), but also because of a tall building next to, by the shadow rays.
i also trayed to solved with maxscript, but im not a scripter, my scripts are always try&error til i get a usable result, it takes long time for me to figure things out.

never the less to solve the problem, i switched to particleflow set up the collisions with the desiered surfaces(building) excluding the rays hitting the shadow emitting objects and a second pf (same as first) with collissions of the shadow emitting objects.to know the the area its enlighted by the sun or shadowed on a hole day in winter and summer the pfs are linked to the sun.the results are not 100% i wanted, but its something i can start working with it

few things i figured out:
rays (particles) sended out of the sun will alwas hit on the same position, because of the targeted direction of the sun, so the emitting area have to be big enough to make sure you hit all the objects (building and shadow emitting building).so therer are a lot of rays you have to send out. eg 1000000 rays givs you 1000 target hits.... lot of calculation
distances betwen emitting rays have to be close enough to get accurate results

maybe there is scripter out there who coould help us solwing this with maxscript!
help would be great!

thanks
pico

3rd Dimentia
06-20-2008, 01:31 PM
Hey Pico, I'm underway with the script. I've attached what I have so far that's using the standard rayintersect, but I do want to explore the possibility of trying the other rayintersect options that ZeBoxx2 mentioned.(thanks) Especially if it will make it faster cause the one I have at the moment is really quite slow. Here's the script as it stands. It's just very basic while testing.

clearlistener()

polyop.SetMapSupport $plane01 0 true

for i = 1 to (polyop.getNumVerts $plane01) do
(
currentVert = polyop.getvert $plane01 i
vertLightCount = 0
for l in lights where classof l == Omnilight do
(
undo off
if distance currentVert l.pos < (l.farAttenEnd) then
(
lit = true
for obj in objects where superclassof obj == GeometryClass and obj.castShadows == on and obj.ishidden == false /*and obj != $plane01*/ while lit == true do
(
theRay = ray (l.pos) (currentVert-l.pos)
intRay = (intersectRay obj theRay)
if intRay != undefined and ((distance intRay.pos currentVert)>20) and ((distance l.pos intRay.pos)<(distance l.pos currentVert ))then
(
lit = false
)
)
if lit == true then
(
vertLightCount += 1
)
)

)


if vertlightCount == 0 then
(
colour = [0,0,0]
)
if vertlightCount == 1 then
(
colour = [255,0,0]
)
if vertlightCount == 2 then
(
colour = [0,255,0]
)
if vertlightCount > 2 then
(
colour = [0,0,255]
)

--format("vertex % is lit by % lights. And should be %\n")i vertLightCount colour
polyop.setVertColor $plane01 0 i colour
)
update $plane01
gc()
redrawViews()

So far it's just hardwired to change the vertcolours of an object called plane01, but over the next few days, I'll be writing a general purpose one with a UI and I'll post it here so anyone can use it.
It works with omni lights and their end falloff range and visible objects that are set to shadow. I found that using Grant Adam's BlurVColor plugin works really nicely with it.
http://www.rpmanager.com/otherGear.htm#BlurVColor

CGTalk Moderation
06-20-2008, 01:31 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.