Curve Control

Topic: version 4 MAXScript Language Improvements /User Interface

You can create CurveControl's in rollouts by using the following:

CurveControl <name> [ <caption> ] [ visible: <boolean> ] [ numCurves: <integer> ] \ [ x_range: <point2> ] [ y_range: <point2> ] [ zoomValues: <point2> ] \ [ scrollValues: <point2> ] [ displayModes: <bitarray> ] \ [ commandMode: <#move_xy | #move_x | #move_y | #scale | #corner | bezier> ] \ [ uiFlags: <array_of_ui_flags> ] \ [ rcmFlags: <array_of_rcm_flags> ] [ asPopup:<boolean> ]

uiFlags:

Any combination of the following flags:

#drawBG, #drawgrid, #upperToolbar, #showReset, #scrollBars, #constrainY,#xvalue

rcmFlags:

Any combination of the following flags:

#move_xy, #move_x, #move_y, #scale, #corner, #bezier, #delete, #all

<curvecontrol>.visible : Boolean

<curvecontrol>.x_range : Point2

<curvecontrol>.y_range : Point2

<curvecontrol>.displayModes : BitArray

<curvecontrol>.commandMode : Name

<curvecontrol>.zoomValues : Point2

Note: The following will automatically perform a zoom extents all:

zoom <curvecontrol> #all

<curvecontrol>.scrollValues : Point2  

<curvecontrol>.curves : Array, read-only

Returns an array of curves of type MAXCurve

Events

In the following events <ci> represents the active Curve Index.

on <curvecontrol> selChanged <ci> <val> do <expr>

Sent when a point is selected or deselected. <val> is the number of points, which are selected.

on <curvecontrol> ptChanged <ci> <val> do <expr>

Sent when a point is changed, <val> is the index of the changed point

on <curvecontrol> tangentChanged <ci> <val> type do <expr>

Sent when a point's in or out tangent is changed, <val> is the index of the changed point type is #inTangent or #outTangent, depending on what changed.

on <curvecontrol> deleted <ci> <val> do <expr>

Sent when a point is deleted, val is the index of the deleted point.

on <curvecontrol> reset <ci> do <expr>

Sent when a curve is reset

ccCurve represents a single curve in a curve control

Properties

<ccCurve>.animatable : Boolean

<ccCurve>.color       : Color

<ccCurve>.disabledColor    : Color

<ccCurve>.width : Integer

<ccCurve>.disabledWidth    : Integer

<ccCurve>.disabledStyle    : Name

<ccCurve>.style : Name

These are the drawing styles for the curves, can be any one of the following:

#solid, #dash, #dot, #dashDot, #dashDotDot, #null, #insideFrame

<ccCurve>.lookupTableSize : Integer

This method sets the size of the Curve Control lookup table. The lookup table allows users of the Curve Control to easily speed up their value access. The default value for the lookup table size is 1000. Used when getValue() is called on the curve.

<ccCurve>.numPoints : Integer

<ccCurve>.points : Array, read-only

Returns a CurvePointsArray

Methods

getValue ccCurve <time_value> <float_x> [lookup:<false>]

Returns a Point2

isAnimated ccCurve <index>

Returns a Boolean value

getSelectedPts ccCurve

Returns a BitArray

setSelectedPts <ccCurve> <bitarray> [#select] [#deSelect] [#clear]

setPoint <ccCurve> <index> <ccpoint> [checkConstraints:<true>]

getPoint <ccCurve> <index>

insertPoint <ccCurve> <index> <ccpoint>

deletePoint <ccCurve> <index>

CurvePointsArray represents an array of curve points. CurvePointValue represents a curve point.

CurvePointValue represents a curve point, you create a curve point like:

ccPoint <pt_point2> <in_point> <out_point2> \ [bezier:<false>] [corner:<false>] [lock_x:<false>] [lock_y:<false>] \ [select:<false>] [end:<false>] [noXConstraint:<false>]

Properties

<ccpoint>.value                  : Point2

<ccpoint>.inTangent       : Point2

<ccpoint>.outTangent             : Point2

<ccpoint>.bezier                 : Boolean

<ccpoint>.corner                 : Boolean

<ccpoint>.lock_x                 : Boolean

<ccpoint>.lock_y                 : Boolean

<ccpoint>.selected               : Boolean

<ccpoint>.end                    : Boolean

<ccpoint>.noXConstraint          : Boolean

Example:

rollout uTestCurveControl "Curve Control"(

-- Curve control Properties

local ccProps = #(

#visible,

#numCurves,

#x_range,

#y_range,

#displayModes,

#zoomValues,

#scrollValues,

#commandMode)

-- Curve properties

local curveProps = #(

#name,

#animatable,

#color,

#disabledColor,

#width,

#disabledWidth,

#style,

#disabledStyle,

#numPoints,

#lookupTableSize)

-- Curve Point properties

local cpProps = #(

#value,

#inTangent,

#outTangent,

#bezier,

#corner,

#lock_x,

#lock_y,

#selected,

#end,

#noXConstraint)

button btn_props "Print Properties"

checkBox chk_visible "Visible" checked:true

checkBox chk_enable "Enable" checked:true

CurveControl cc_test "Curve Control:"  

height:200

width:400

align:#center

numCurves:2

visible:true

x_range:[-100,100]

y_range:[-100,100]

scrollValues:[-100,100]

commandMode:#move_xy

-- The following parameters default to all flags if not specified

--uiFlags:#(#drawBG, #drawgrid, #upperToolbar, #showReset, #scrollBars, #constrainY, #xvalue)

rcmFlags:#(#delete)

asPopup:false

on chk_visible changed state do cc_test.visible = state

on chk_enable changed state do cc_test.enabled = state

on uTestCurveControl open do

(

local colors = #(red, green, blue)

local styles = #(#solid, #dash, #dot, #dashDot, #dashDotDot, #null, #insideFrame)

local num = cc_test.numCurves

-- Initialize curve properties

for i=2 to num do

(

local crv = cc_test.curves[i]

local ci = ((mod (i-1) colors.count)+1) as integer

local si = ((mod (i-1) styles.count)+1) as integer

crv.name = "Curve" + i as string

crv.color = colors[ci]

crv.disabledColor = colors[ci]*0.5

crv.style = styles[si]

--crv.width = crv.disabledWidth = i

crv.numPoints = i*2

local del = (cc_test.x_range.y - cc_test.x_range.x)/(crv.numPoints-1)

--format "del:%\n" del

-- Place intermediate points equally spaced

for j=1 to crv.numPoints do

(

local cp = crv.points[j]

format "% end: % -> " j cp.end

--cp.corner = true

cp.value = [cc_test.x_range.x+(j-1)*del, cp.value.y]

cp.inTangent = [0.2,0.2]

cp.outTangent = [0.2,-0.2]

crv.points[j] = cp

format "%\n" crv.points[j].end

format "value: %\n" crv.points[j].value

)

)

)

on btn_props pressed do

(

local tab = "\t"

-- print the CC properties

format "Curve Control Properties\n"

for p in ccProps do

format (tab + "% : %\n") (p as string) (getProperty cc_test p)

format (tab + "Curves:\n")

tab += "\t"

for i=1 to cc_test.numCurves do

(

local crv = cc_test.curves[i]

-- print each Curve's properties

(tab + "Curve%\n") i

for p in curveProps do

format (tab + "\t% : %\n") (p as string) (getProperty crv p)

format (tab + "\tPoints:\n")

for j=1 to crv.numPoints do

(

local cp = crv.points[j]

format (tab + "\t\tPoint%\n") j

-- Print each curve point properties

for pp in cpProps do

format (tab + "\t\t\t% : %\n") (pp as string) (getProperty cp pp)

)

)

)

-- Curve control event handlers

on cc_test selChanged ci val do format "curve % numSelected : %\n" ci val

on cc_test ptChanged ci val do format "curve % ptChanged : %\n" ci val

on cc_test tangentChanged ci val type do format "curve % tangentChanged : % %\n" ci val (type as string)

on cc_test deleted ci pi do format "curve % deleted : %\n" ci pi

on cc_test reset ci do format "curve % resetted\n" ci

)

curveFloater = newRolloutFloater "Curve Control Test" 500 400

addRollout uTestCurveControl curveFloater

See also