Notifications
Clear all

[Closed] IntersectRay with scale animation

Hello maxscript guys and girls,

I need your help.
I’am trying to do a simple scale_script to interactively make a bunch of cubes scale up when a plane pass in front of them. My actual script make the cubes pop up from scale 0 % to 100 % but i want them to gradually scale up or down during 10 frames.

In fact, the cubes launch a ray and intersectRay see if the ray hit the plane surface. I want when the ray hit the plane the cube grows up by 10% per frame to 100 % and when the ray stops to hit the plane the cube gradually grows down by 10% per frame to 0%.

This is my actual script :

DependsOn $Plane001
 
   varRay = intersectRay $Plane001 (ray $Box001.pos [0,-1,0])
   if varRay != undefined then return [0,0,0] else return [1,1,1]
   

Do you have an idea to do this kind of effect ?
Thank you for your help.

7 Replies

do you want to use intersectRay with a script controller?

Hello DenisT,

Yes, i put the script in the scale controller script of each cube.
The cubes are stacked to form a matrix or a kind of brick wall.

what’s the bigger problem? to make the scale fading-in/out or make the using of intersectRay fast enough to be used?

the intersectRay is too slow for using in script controllers.

In fact, i have only 97 cubes and the reactivity of the intersectRay is fast enough for me by now.
My bigger problem is to make the cubes scale up by 10% step to 100% when the ray hits the plane and make the cubes scale down by 10% to 0% when the ray doesn’t hit the plane.

These are the steps, i guess, for the script :

  • the ray of the cube N hit the plane
  • instead of poping from 0 to 100%, the cube scale up from 0 to 100% by 10 % steps (10 frames)
  • the plane moves and the ray doesn’t hit it no more.
  • the cube N scale down to 0 by 10 % steps (10 frames)

Do you have an idea to do it ?

i will show below how to make an animated fading of a value using custom attribute…


  global FadeAttr = attributes FadeAttr 
  (
  	parameters params rollout:params
  	(
  		fade type:#integer default:1 ui:ui_fade
  		range type:#floatTab tabsize:3 ui:(ui_lower_limit,ui_upper_limit,ui_value_scale)
  		time type:#time animatable:off 
  		value type:#float animatable:off		
  	)
  	rollout params "Fade Parameters" 
  	(
  		group "Fade: "
  		(
  			radiobuttons ui_fade labels:#("In", "None", "Out") align:#left offset:[10,0]
  		)
  		group "Value: "
  		(
  			spinner ui_lower_limit "Min: " range:[-1e9,1e9,0] type:#float fieldwidth:54 align:#right offset:[0,-2]
  			spinner ui_upper_limit "Max: " range:[-1e9,1e9,0] type:#float fieldwidth:54 align:#right offset:[0,0]
  			spinner ui_value_scale "Scale: " range:[-1e9,1e9,0] type:#float fieldwidth:54 align:#right offset:[0,0]
  		)
  	)
  )
  (
  	delete objects
  	b = box name:"b" height:0 isselected:on
  	s = b.height.controller = Float_Script()
  	attr = createinstance FadeAttr range:#(10,100,10) 
  	append b.baseobject.custattributes attr
  	s.addobject "fade" attr
  
  	ss  = ""
  	ss += "v = fade.value + (f - fade.time)*fade.range[3]*((2 - fade.fade) as integer);
"
  	ss += "v = amax fade.range[1] (amin fade.range[2] v)
"
  	ss += "if fade.value != v do fade.value = v
"
  	ss += "if fade.time != f do fade.time = f
"
  	ss += "v"
  
  	s.setexpression ss
  	f = attr.fade.controller = Bezier_Float()
  	k = addnewkey f 0f  
  	k.value = 1 -- in
  	k = addnewkey f 15f  
  	k.value = 2 -- none
  	k = addnewkey f 30f  
  	k.value = 2 -- none
  	k = addnewkey f 35f  
  	k.value = 3 -- out
  	
  	f.keys.outTangentType = f.keys.inTangentType = #step
  	
  	ok
  )
  

i add the attribute to the object just to demonstrate how the setup works. technically it can be added to a controller to be invisible for user.
also to make your life not too easy i’m not showing how to make the TRUE backward playback try to solve it yourself.

Hello DenisT,

Thank you a lot for your help.
Your script works very well.

I will analyse it to understand the way you make it and adapt it for my purpose.
I’am not a great maxscript coder but i learn every day.

Thank you very much.
Cheers.