BindToPoint and BindToFace are modifiers that allow you to link points on an object to points or faces on another object. They can be thought of as Linked XForm modifiers that let you link to sub-object parts of another object.
Both modifiers have no properties and essentially no UI. They are entirely operated through a set of MaxScript functions. Things to keep in mind when working with these modifiers:
(knotIndex*3-1)
(ie. the index to be passed into the Bind() function for the 5th knot on a spline would be (5*3-1) = 14).
Two new global structs are defined that contain functions used to control the bind modifiers: toPointOps
and toFaceOps
.
The first argument for all the functions is always an instance of the modifier you're working with (ie. a BindToFace modifier for toFaceOps and a BindToPoint modifier for toPointOps.)
The syntax for both sets of functions are the same unless otherwise noted.
The available functions are:
- toPointOps.SetBindNode <bindToPointModifier> <boundNode> <deformerNode>
- toPointOps.GetBindNode <bindToPointModifier>
- toPointOps.Bind <bindToPointModifier> <boundPointIndex> <deformerPointIndex>
- toPointOps.Unbind <bindToPointModifier> <boundPointIndex>
- toPointOps.GetBindIndex <bindToPointModifier> <boundPointIndex>
- toPointOps.SetNumBinds <bindToPointModifier>
toPointOps.SetNumBind bindMod 200
.
- toPointOps.GetNumBinds <bindToPointModifier>
toFaceOps
functions is the Bind
function:
- toFaceOps.Bind <bindToFaceModifier> <boundNode> <boundPointIndex> <deformerPointIndex>
The following scripts were used to create the sample scene included with this plugin. If you load the scene, and delete the existing Bind modifiers, you can run these scripts to see how they work.
Example of using the BindToFace modifier:
-- Create the bind modifier
bMod = BindToFace()
-- Assign the deformer node to the modifier
toFaceOps.SetBindNode bMod $BoundNode $DeformerNode
-- Loop through all the verts on the boundNode
for i in 1 to $BoundNode.numVerts do (
-- Make a ray pointing from a vertex on the boundNode towards the deformerNode
local r = Ray (GetVert $BoundNode i) [0,0,-1]
-- Intersect it to see if it hits a face
local hitRes = IntersectRayEx $DeformerNode r
-- If it hit, bind the vertex to the hit face
if (hitRes != undefined) then (
toFaceOps.Bind bMod $BoundNode i hitRes[2]
)
)
-- Actually add the modifier to the boundNode
-- (you can do this whenever you want, really)
AddModifier $BoundNode bMod
Example of using the BindToPoint modifier:
-- Simple function to get the closest vertex on a mesh to a given point
fn GetClosestVert pnt meshObj =
(
local closestIdx, dist, closest = 999999999
for i in 1 to meshObj.numVerts do (
dist = distance pnt (GetVert meshObj i)
case of (
(dist == 0.0): return i
(dist < closest): (
closest = dist
closestIdx = i
)
)
)
return closestIdx
)
-- Create the bind modifier
bMod = BindToPoint()
-- Add the modifier
AddModifier $BoundSpline bMod
-- Assign the deformer node to the modifier
toPointOps.SetBindNode bMod $BoundSpline $DeformerTeapot
-- Loop through all the knots and bind them to the
-- closest vertex on the teapot
for i in 1 to (NumKnots $BoundSpline) do (
local p = GetKnotPoint $BoundSpline 1 i
local closestIdx = GetClosestVert p $DeformerTeapot
-- Assign knot i to the closest vert on the teapot
-- Note that knot "i" is referred to as point "(i*3-1)"
toPointOps.Bind bMod (i*3-1) closestIdx
)
03.07.2001 - Created.