MaxScript: Converting between FFD Space and World Space
This code snippit will only be useful to a very small amount of people out there. In 3DS Max if you’re working with a Free Form Deformation (FFD) modifier, it operates in its own modifier space which is a pain in the butt to work with. This code will convert to and from the different spaces.
(
-- This script converts from FFD space to world space and back again.
-- Neil Marshall 12/31/2011
-- If you use this code, give me credit.
fn FFDSpaceToWorldSpace obj ffd controlPoint =
(
if classOf controlPoint != Point3 then
(
print "Error: You need to pass in a point 3 to properly convert a FFD to world space"
return undefined
)
objTM = obj.objecttransform
modTM = (getModContextTM obj ffd) * ffd.lattice_transform.value
modBBMin = getModContextBBoxMin obj ffd
modBBMax = getModContextBBoxMax obj ffd
size = modBBMax - modBBMin
thePoint = modBBMin * inverse ffd.lattice_transform.rotation + (controlPoint * size) * modTM * objTM
return thePoint
)
fn WorldSpaceToFFDSpace obj ffd worldSpace =
(
objTM = obj.objecttransform
modTM = (getModContextTM obj ffd) * ffd.lattice_transform.value
modBBMin = getModContextBBoxMin obj ffd
modBBMax = getModContextBBoxMax obj ffd
size = modBBMax - modBBMin
thePoint = (worldSpace * (inverse objTM) * (inverse modTM) - modBBMin) / size
return thePoint
)
while $tester != undefined do
(
delete $tester
)
obj = $Box01
animateAll obj.modifiers[1]
print ("Before FFD Space: " + obj.modifiers[1].control_point_3 as string)
thePoint = FFDSpaceToWorldSpace obj obj.modifiers[1] obj.modifiers[1].control_point_3
if thePoint != undefined then
(
print ("WorldSpace: " + thePoint as string)
point name:"tester" pos:thePoint
obj.modifiers[1].control_point_3 = WorldSpaceToFFDSpace obj obj.modifiers[1] thePoint
print ("After FFD Space: " + obj.modifiers[1].control_point_3 as string)
)
""
)
Comments off











