Skip to content

Instantly share code, notes, and snippets.

@Swordslayer
Created February 11, 2022 15:22
Show Gist options
  • Save Swordslayer/03752ddcd7c68fbf8cff2503223328fd to your computer and use it in GitHub Desktop.
Save Swordslayer/03752ddcd7c68fbf8cff2503223328fd to your computer and use it in GitHub Desktop.
Setting points of the DataChannel modifier curve control.
(
local obj = Sphere segs:64 isSelected:on
local dataChannel = DataChannelModifier()
addModifier obj dataChannel
local iGlobal = (dotNetClass "Autodesk.Max.GlobalInterface").Instance
local CURVEP_BEZIER = bit.shift 1 0
local CURVEP_CORNER = bit.shift 1 1
fn convertPoint pt =
(
local curvePt = iGlobal.CurvePoint.Create()
curvePt.P = iGlobal.Point2.Create pt.value.x pt.value.y
curvePt.In = iGlobal.Point2.Create pt.inTangent.x pt.inTangent.y
curvePt.Out = iGlobal.Point2.Create pt.outTangent.x pt.inTangent.y
if pt.bezier do curvePt.Flags += CURVEP_BEZIER
if pt.corner do curvePt.Flags += CURVEP_CORNER
return curvePt
)
fn setCurvePts curve pts =
(
curve.NumPts = pts.count
for i = pts.count to 1 by -1 do curve.SetPoint currentTime.ticks (i - 1) (convertPoint pts[i]) on off
)
dataChannel.AddOperator Operator_VertexInput.classID[1] Operator_VertexInput.classID[2] -1
dataChannel.AddOperator Operator_Normalize.classID[1] Operator_Normalize.classID[2] -1
dataChannel.AddOperator Operator_Curve.classID[1] Operator_Curve.classID[2] -1
dataChannel.AddOperator Operator_VertexOutput.classID[1] Operator_VertexOutput.classID[2] -1
local inputOp = dataChannel.operators[1]
local curveOp = dataChannel.operators[3]
local outputOp = dataChannel.operators[4]
inputOp.input = 0
inputOp.xyz = 3
outputOp.output = 4
local curvePoints = #(
ccPoint [0, 0] [0, 0] [.15, 0] bezier:on corner:on,
ccPoint [.5, 2] [-.2, 0] [.2, 0] bezier:on,
ccPoint [1, .2] [-.15, 0] [0, 0] bezier:on corner:on
)
local curve = iGlobal.Animatable.GetAnimByHandle (getHandleByAnim curveOp.curve[1].object)
setCurvePts curve curvePoints
notifyDependents obj
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment