Notifications
Clear all

[Closed] curveControl using the wrong values

i made a snippet to show how to bind curve control curve and track view curve.


try (destroydialog CurveControlToTrack) catch()
rollout CurveControlToTrack "Curve Control to Track" width:404 height:312
(
	CurveControl ccc width:400 height:300 numCurves:1 pos:[2,2] \
		x_range:[0,100] y_range:[-100,100] scrollValues:[-100,100] commandMode:#move_xy \   
		asPopup:false

	local track_node, track 
	on CurveControlToTrack close do try
	(
		trackviews.close "Curve Control To Track"
		deleteTrackViewNode track_node
--		if not (trackviews.isOpen "Curve Control To Track") do trackviews.delete "Curve Control To Track"
	)
	catch()

	local const = 0.25 * (1.0 - 0.25) -- THE MAGIC NUMBER
	fn updateTrackCurve curve:1 point: type: event: = if track != undefined and track.keys.count == 3 do
	(
		cc = ccc.curves[curve]
		-- curve control cc points 
		p1 = cc.points[1]
		p2 = cc.points[2]
		p3 = cc.points[3]
		-- track curve keys
		k1 = track.keys[1]
		k2 = track.keys[2]
		k3 = track.keys[3]
--		format "%: % % %
" event curve point type
		
		case event of
		(
			#selChanged: 
			(
				for k=1 to 3 do track.keys[k].selected = cc.points[k].selected
			)
		)

		k1.outTangentLength = p1.outTangent.x/(p2.value.x - p1.value.x)
		k1.outTangent = p1.outTangent.y*const/p1.outTangent.x
		k1.value = p1.value.y
		k1.time = p1.value.x

		k2.inTangentLength = p2.inTangent.x/(p1.value.x - p2.value.x)
		k2.inTangent = -p2.inTangent.y*const/p2.inTangent.x
		k2.outTangentLength = p2.outTangent.x/(p3.value.x - p2.value.x)
		k2.outTangent = p2.outTangent.y*const/p2.outTangent.x
		k2.value = p2.value.y
		k2.time = p2.value.x

		k3.inTangentLength = p3.inTangent.x/(p2.value.x - p3.value.x)
		k3.inTangent = -p3.inTangent.y*const/p3.inTangent.x
		k3.value = p3.value.y
		k3.time = p3.value.x
	)
	
	on CurveControlToTrack open do
	(
		trackviews.open "Curve Control To Track" width:800 height:400
		trackviews.setCurrent "Curve Control To Track"
		track_node = newTrackViewNode "TrackView"
		track = bezier_float()
		addTrackViewController track_node track "Curve"

		cc = ccc.curves[1]
		cc.numPoints = 3 
		cc.points[1] = ccPoint [0,0] [0,0] [0,0] bezier:on corner:on lock_x:off lock_y:off noXConstraint:on 
		cc.points[2] = ccPoint [50,50] [-33,0] [33,0] bezier:on corner:off lock_x:off lock_y:off noXConstraint:on 
		cc.points[3] = ccPoint [100,0] [-33,0] [0,0] bezier:on corner:on lock_x:off lock_y:off noXConstraint:on 
		cc.points[1].outtangent = [33,0]
		zoom ccc #all
		ccc.scrollValues = [-23,-40]
		ccc.zoomValues = [3,1.5]
		
		addnewkey track 0
		addnewkey track 50
		addnewkey track 100
		updateTrackCurve curve:1
		
		trackviews.setFilter "Curve Control To Track" #default
		trackviews.current.expandTracks()
		trackviews.current.selectTrack track on
		trackviews.current.zoomSelected()
--		trackviews.current.ui.showTrackWindow = off
		trackviews.setFilter "Curve Control To Track" #animatedTracks
	)
	on ccc selChanged c p do updateTrackCurve curve:c point:p type:type event:#selChanged
	on ccc ptChanged c p do updateTrackCurve curve:c point:p type:type event:#ptChanged
	on ccc tangentChanged c p type do updateTrackCurve curve:c point:p type:type event:#tangentChanged
)
createdialog CurveControlToTrack

try to edit the curve control points and check the track curve changes…

everyone is free to extend the snippet to support other features…

0.1875 is some magic number. it’s 0.25 * (1.0 – 0.25) or (3./16)…
some sort of golden ratio i couldn’t find any sense for this number.

0.1875 is some magic number. it’s 0.25 * (1.0 – 0.25) or (3./16)…
some sort of golden ratio i could find any sense for this number.

hah.! thanks for the code! disappointed by maxscript help on this issue though, not a single line is mentioned about how the in/out tangents are computed, but there’s a detailed para on in/out tangent lengths! am I missing something? :surprised. (also 0.1875 * 240 = 45, Tan 45 = 1 )

it’s an effect, not a cause…

Wow! Great information! Thank you so much for all this. I’ll get back to work on it right away. Thanks again!

EDIT:

DANG! Denis, I just ran your code! This is exactly what I was trying to do but couldn’t! Outstanding! I’m going to learn a lot from this. Thank you so, so much!

there is the list of curve control events:
[left]selChanged,
ptChanged,
tangentChanged,
deleted,
reset,
rightClick

is there any way to catch cc point tangent TYPE CHANGE event?
yes, there is!
who knows how?
[/left]

I thought maybe you could use a mouse click event handler to test the point props on and after changing the tangent types… but I was wrong. Here’s what I tried:

   
  fn tangentCheck val =
   (
       val = #()
    		
       for i=1 to cc_test.numCurves do
       (
    	   local crv = cc_test.curves[i]
    	   for j=1 to crv.numPoints do 
    	   (
    		   local cp = crv.points[j]
    		   for pp in cpProps where pp == #bezier or pp == #corner collect
    		   (
    			   append val (getProperty cp pp)
    		   )
    	   )
       )
    		
       return val
   )
    	
   on uTestCurveControl lbuttondown val do 
   (
    		
       tangentTypes = tangentCheck check1
   )
    
   on uTestCurveControl lbuttonup val do 	
   (
       tangentTypesChanged = tangentCheck check2
    	
       diff = for i=1 to tangentTypes.count where tangentTypes[i] != tangentTypesChanged[i] collect i
       if diff.count > 0 then print "Tangent Type Changed" else print "T'ain't no change, sucka!"
    
   )
It collects an array of tangent type properties on and after a left mouse click and then checks to see if anything changed. The problem is that because you have to click on a menu item in the right click menu I don't think the left click even registers.

What's the right answer? :)

Denis, the suspense is killing me on this one! What was the right answer? How do you catch a cc point tangent TYPE CHANGE event? It’s way beyond my skills.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

use when construct for curve control target reference. to get the reference use refs.dependents method for ccCurve…
i don’t have max open, so it’s something like:


when topology (refs.dependents <ccCurve>)[1] changes do <whatever you need>

That is awesome. Thanks.

Page 2 / 2