BindPoints


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:


MaxScript Access:

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>
Assigns which node should be used to drive deformations.
BoundNode is the node that will be deformed (read: has the BindToPointModifier applied).
DeformerNode is the node that will drive the deformation.
toPointOps.GetBindNode <bindToPointModifier>
Returns what node is assigned as the deformer node, or undefined if there isn't one.
toPointOps.Bind <bindToPointModifier> <boundPointIndex> <deformerPointIndex>
Binds the point with index boundPointIndex on the boundNode to follow the point with index deformerPointIndex on the deformerNode.
toPointOps.Unbind <bindToPointModifier> <boundPointIndex>
Unbinds the point with index boundPointIndex on the boundNode.
toPointOps.GetBindIndex <bindToPointModifier> <boundPointIndex>
Returns the which point the boundPointIndex is following.
toPointOps.SetNumBinds <bindToPointModifier>
You can think of these modifiers as holding a dumb array of "bind records" used for deforming. The array can get resized with Get/SetNumBinds(), though you shouldn't normally need to do that.
The only time you might want to do this is if you cut the modifier off an object with (say) 500 points, and paste it onto one with 200 points. In this case, the bind modifier still has 500 "bind records", 300 of which are now pointless and can be thrown away by calling toPointOps.SetNumBind bindMod 200.
toPointOps.GetNumBinds <bindToPointModifier>
Gets the number of recorded binds.
The only difference for the toFaceOps functions is the Bind function:
toFaceOps.Bind <bindToFaceModifier> <boundNode> <boundPointIndex> <deformerPointIndex>
These arguments are the same as the toPointOps version, except the second argument is now a reference to the boundNode.

Back To Top...


Example:

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
)

Back To Top...


Known Bugs/Limitations:

Back To Top...


History:

03.07.2001 - Created.

Back To Top...


Bug reports/comments/suggestions: john@johnburnett.com