PDA

View Full Version : IntersectRay Help!


viro
03-25-2009, 05:44 PM
I am taking our current intersectRay functionality that works by using a pick button and adapting it to work with a list box and an array as apposed to the one object version used by the pick button. I am not sure if I am going about this the right way and I wanted to get some feedback on what I am missing. Essentially what I am trying to do is to take our current machine rigs and give them the ability to drive along multiple ground objects picked by the list box. I have been trying to get it to work for a couple days now. :banghead: I hope someone can give me some help on what I am doing wrong.

ca = custAttributes.getDef $.modifiers[1].controls
attributes controls
redefine:ca
(
parameters main rollout:controlsR
(

collisionObj type:#maxObject

)
local list=#()
--#########################################
--Functions
--#########################################

fn intersect rayCas =
(
if collisionObj!=undefined and (isValidNode collisionObj.node) then
(
intersectRay collisionObj.node rayCas
)else
(
undefined
)
)
--#########################################
--Rollouts
--#########################################
rollout controlsR "controls" width:160 height:1000
(

group "ground"
(
listbox listObj "Ground Objects:" height:5
button remove "remove" across:2
pickbutton add "add" across:2
)

--when the add button is pressed do this
on add picked obj do
(
--Make sure the object is an editabale mesh and if so go to the next line
if classOf obj == Editable_mesh then
(
--add the picked object to the list array
for i in 1 to (listObj.items.count) do
(
collisionObj= (listObj.items[i])
collisionObj=nodeTransformMonitor node:obj forwardTransformChangeMsgs:false
)

print collisionObj
(listObj.items) = append(listObj.items) (obj.name)
list = (listObj.items)

)

)

on remove pressed do
(
collisionObj=undefined
print collisionObj
--if array is not empty and selected is not empty then
if (listObj.selection) != 0 then
(
--delete the selected object from the lsit
(listObj.items) = deleteItem (listObj.items) listObj.selection
)
)
on controls open do
(

(listObj.items)=list

)
)

)
--Positon Script Controller
--variables
rayObj=--Ray casting object
master=--controll object attribute holder.control
masterObj=--control Object
--Script in controler
rayCas=(ray rayObj.pos (-rayObj.transform.row3))
hit=master.intersect rayCas

if hit==undefined then
(masterObj.pos)
else
(hit.pos)r

viro
03-26-2009, 12:00 AM
Well I got most of it sorted out by taking a look at Pen's tutorial on weak referencing. http://paulneale.com/tutorials/Scripting/weakReferences/weakReferences.htm

Now I need to figure out how to get the intersectRay function to work with an array of objects. Heres what I have working now. Obviously this is just taking the first item in the array and using it. I tried a for loop already to with no luck. Any ideas?
fn gethit rayV = ( if ground[1]!=undefined and (isValidNode ground[1].node) then ( intersectRay ground[1].node rayV ) else ( undefined ) )

CGTalk Moderation
03-26-2009, 12:00 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.