PDA

View Full Version : Maxscript / IntersectRay


BlackWhite
11-07-2010, 06:41 PM
Hi everyone!

I really need your help about something in Maxscript...

What I want to do is launch a ray from each point helper generated by an 3D array and look if the rays intersect the box named "box01". My problem is: I dont know how to use in loop all point helper position as origin for a ray and then if the ray intersect the box affect its size.

Thank you very much!
Alex

This is the script I did /////////////////////

Box length:22 width:38 height:48 pos:[13,32,0]

(
local array = #()
c = 20
global l = 6
global w = 6
global h = 4

ML = (c * L + c) / 2
MW = (c * W + c) / 2
MH = (c * H + c) / 2

for x = 1 to l do
(
array[x]=#()
for y = 1 to w do
(
array[x][y]=#()
for z = 1 to h do
(
array[x][y][z]=Point size:1 pos:[((x*c)-ml),((y*c)-mw),((z*c)-c)] wirecolor:[255,255,255]
)
)
)

(
for i in (getClassInstances point) do
(
r0 = Ray i.pos [100,150,150] -- Ray [pos] [dir]
IR = intersectRay $box01 r0

(
if IR != undefined do
(
i.size = i.size+2
)
)
)
)
)

TheGrak
11-08-2010, 06:18 AM
I took a shot at rewriting your code. I'm not sure this will work, but it has formatting/scope:


( --start
local myBox = Box length:22 width:38 height:48 pos:[13,32,0]
local myUniqueArrayName = #()
local c = 20
local l = 6
local w = 6
local h = 4
local ML = (c * L + c) / 2
local MW = (c * W + c) / 2
local MH = (c * H + c) / 2
--
for x = 1 to l do
(
myUniqueArrayName[x]=#() --?
for y = 1 to w do
(
myUniqueArrayName[x][y]=#() --?
for z = 1 to h do
(
myUniqueArrayName[x][y][z]=Point size:1 pos:[((x*c)-ml),((y*c)-mw),((z*c)-c)] wirecolor:[255,255,255] --?
)
)
)
--
local numberOfPoints = getClassInstances point
for i to (numberOfPoints.count) do
(
r0 = Ray numberOfPoints[i].pos [100,150,150] -- Ray [pos] [dir]
local IR = intersectRay myBox r0
if IR != undefined do (numberOfPoints[i].size += 2)
)
--
) --end


Hope this helps! :)

TheGrak
11-09-2010, 12:31 AM
This code actually works! :)


( --start
local myBox = Box length:22 width:38 height:48 pos:[13,32,0]
local myUniqueArrayName = #()
local c = 20
local l = 6
local w = 6
local h = 4
local ML = (c * L + c) / 2
local MW = (c * W + c) / 2
local MH = (c * H + c) / 2
--
for x = 1 to l do
(
myUniqueArrayName[x]=#()
for y = 1 to w do
(
myUniqueArrayName[x][y]=#()
for z = 1 to h do
(
myUniqueArrayName[x][y][z]=Point size:1 pos:[((x*c)-ml),((y*c)-mw),((z*c)-c)] wirecolor:[255,255,255]
)
)
)
--
select $Point*
try local pHelpersInScene = $ as array catch()
for i = 1 to (pHelpersInScene.count) do
(
local r0 = Ray pHelpersInScene[i].pos [100,150,150] -- Ray [pos] [dir]
local IR = intersectRay myBox r0
if IR != undefined do (pHelpersInScene[i].size += 10)
)
--
) --end


I didn't use the getClassInstances, instead I used 'select $Point*', then turned that into an array.

CGTalk Moderation
11-09-2010, 12:31 AM
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.