Notifications
Clear all

[Closed] Having Multi surface in intersectRay

Hi
In a demo reel i’ve seen there was a listbox the guy adds some surfaces to it and the object has contact with the listbox items surface.
Is it possible to have Multi surface in intersectRay o

Thanks in advance

16 Replies
4 Replies
(@denist)
Joined: 11 months ago

Posts: 0

Are you asking about Ray-Mesh or Mesh-Mesh intersect?
If ray intersection is what you are looking for you can use intersectRayScene, and sort the result by distance to hit for example

(@scriptlover)
Joined: 11 months ago

Posts: 0

Jorge Thank you very much your script is so understandable.Thank you very much

Denis about two objects’ interaction the only thing that i just know is The IntersectRay. I didn’t know there is [b] Mesh-Mesh intersect. How are they different?

[/b]

(@polytools3d)
Joined: 11 months ago

Posts: 0

Would it be faster than intersectRay() if you have thousands of objects but only need to test against 2 or 5 of them?

(@denist)
Joined: 11 months ago

Posts: 0

it will not… the intersectRayScene method iterates whole scene geometry.
it would be better to make a mapped version of intersectRay and pass a list of searching-in nodes

By copying and attaching those surfaces together, yes… It’s possible…

Thanks for the reply
But when you attach some surfaces together actually it becomes one surface againe.

If you search the ” car rigging (Ferrari Enzo) ” on Youtube the guy first detach some part of a surface (a ray surface) then adds the detached surface to a listbox then car had effect on all detached surfaces as well.

In this case you have to make a copy of these surfaces first, than attach them together and make an EditableMesh from them. It will be faster then leaving those objects as EditablePoly objects.

Or you can iterate over all the surfaces one by one in the list.

I’m curious about the technique. not the solution. so i asked : technically is it possible one object has intersectray with more than one object (as surface) not attached one. maybe the guy didn’t use the intersectray technique .
Maybe he used conform and attached surface … method ?

The used technique only the developer knows.

But regarding your question,
technically is it possible one object has intersectray with more than one object (as surface) not attached one
, yes it is possible, and one way is the one already mentioned, iterate over all the surfaces.

Even when you don’t want to know the solution, it is implicit in the technique.

Or…you could just use the new anim constraints that came with 3dsamx2016 SP1.

Maybe you should inspect those 2 compounds:

GetRayToSurfaceIntersection
FilterAndSortRayIntersections

Hey Jorge
Maybe PI3c3 told the answer but I’m blind to see, would you please explain it a little more.If it is the answer , So i didn’t understand it well.

1 Reply
(@polytools3d)
Joined: 11 months ago

Posts: 0

Something like this:

(
 	
 	delete objects
 	P1 = plane length:50 width:50 lengthsegs:5 widthsegs:5 pos:[-25, 25,20] wirecolor:red name:"P1"
 	P2 = plane length:50 width:50 lengthsegs:5 widthsegs:5 pos:[ 25, 25,20] wirecolor:blue name:"P2"
 	P3 = plane length:50 width:50 lengthsegs:5 widthsegs:5 pos:[-25,-25,20] wirecolor:green name:"P3"
 	P4 = plane length:50 width:50 lengthsegs:5 widthsegs:5 pos:[ 25,-25,20] wirecolor:yellow name:"P4"
 	select #(P1,P2,P3,P4)
 	modpanel.addmodtoselection (noisemodifier scale:50 strength:[0,0,25] animate:on)
 
 	gs = geosphere radius:5 pos:[-25,25,50] wirecolor:white name:"Ball"
 
 	scr = "dependsOn $P1 $P2 $P3 $P4 $Ball
"
 	scr += "(
"
 	scr += "zPos = intersectRay $P1 (ray $Ball.pos [0,0,-1])
"
 	scr += "if zPos == undefined do zPos = intersectRay $P2 (ray $Ball.pos [0,0,-1])
"
 	scr += "if zPos == undefined do zPos = intersectRay $P3 (ray $Ball.pos [0,0,-1])
"
 	scr += "if zPos == undefined do zPos = intersectRay $P4 (ray $Ball.pos [0,0,-1])
"
 	scr += ")
"
 	scr += "if zPos != undefined then zPos.pos.z + $Ball.radius else 50
"
 
 	gs.pos.controller.z_position.controller = float_script()
 	gs.pos.controller.z_position.controller.script = scr
 	
 	animate on
 	(
 		at time 25 gs.pos = [25,25,50]
 		at time 50 gs.pos = [25,-25,50]
 		at time 75 gs.pos = [-25,-25,50]
 		at time 100 gs.pos = [-25,25,50]
 	)
 	
 	max select none
 	
 )

Thanks man
Nice try, i do my best to see can i make it better

Thanks PI3c3 and MGernot for your comment

1 Reply
(@polytools3d)
Joined: 11 months ago

Posts: 0

Of course you can make it better. It is just a quick dirty example.

Here is another example. You could store the ‘collision objects’ in a CA and add it to the Ball node if you wanted. That way you can add and remove nodes for collision.

(
 	 delete objects
 	
 	max modify mode
 	 P1 = plane length:50 width:50 lengthsegs:5 widthsegs:5 pos:[-25, 25,20] wirecolor:red name:"P1"
 	 P2 = plane length:50 width:50 lengthsegs:5 widthsegs:5 pos:[ 25, 25,20] wirecolor:blue name:"P2"
 	 P3 = plane length:50 width:50 lengthsegs:5 widthsegs:5 pos:[-25,-25,20] wirecolor:green name:"P3"
 	 P4 = plane length:50 width:50 lengthsegs:5 widthsegs:5 pos:[ 25,-25,20] wirecolor:yellow name:"P4"
 	 select #(P1,P2,P3,P4)
 	 modpanel.addmodtoselection (noisemodifier scale:50 strength:[0,0,25] animate:on)
  
 	ramp = tube radius1:25 radius2:45 height:20 heightsegs:1 capsegs:3 sides:30 pos:[0,0,-5] wirecolor:orange name:"Ramp"
 	addmodifier ramp (bend bendangle:-20 bendaxis:2)
 	
 	 gs = geosphere radius:5 pos:[-25,25,50] wirecolor:white name:"Ball"
  
 	scr  = "dependsOn $P1 $P2 $P3 $P4 $Ramp $Ball
"
 	scr += "(
"
 	scr += "collisionPosZ = 0
"
 	scr += "collide = false
"
 	scr += "for j in #($P1,$P2,$P3,$P4,$Ramp) do
"
 	scr += "(
"
 	scr += "rayPos = $Ball.pos
"
 	scr += "rayPos.z = 100
"
 	scr += "zPos = intersectRay j (ray rayPos [0,0,-1])
"
 	scr += "if zPos != undefined and zPos.pos.z > collisionPosZ do
"
 	scr += "(
"
 	scr += "collisionPosZ = zPos.pos.z
"
 	scr += "collide = true
"
 	scr += ")
"
 	scr += ")
"
 	scr += ")
"
 	scr += "if collide then collisionPosZ + $Ball.radius else 50
"
  
 	 gs.pos.controller.z_position.controller = float_script()
 	 gs.pos.controller.z_position.controller.script = scr
 	 
 	 animate on
 	 (
 		 at time 25 gs.pos = [25,25,50]
 		 at time 50 gs.pos = [25,-25,50]
 		 at time 75 gs.pos = [-25,-25,50]
 		 at time 100 gs.pos = [-25,25,50]
 	 )
 	 
 	 max select none
 	playAnimation()
 )
Page 1 / 2