Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

FFD Control Point to World Space and Back Again

FFD Control Point to World Space and Back Again

Anonymous
Not applicable
334 Views
1 Reply
Message 1 of 2

FFD Control Point to World Space and Back Again

Anonymous
Not applicable
I'm trying to convert FFD points from their custom space to world space and back again, but There is some error in the converting back portion. For some reason 0.83333 gets added to the coordinates. e.g. On control_point_1 it goes from ->

"Orig: "
"Point 1: "
"Final: "

The actual position of my object in world space doesn't matter, it always adds 0.83333 to the coordinate. Can anyone see what I'm doing wrong?

 fn GetRealWorldCoords obj ffd ffdPoint =
(
print ("Orig: " + ffdPoint as string)
objTM = obj.objectTransform
modTM = (getModContextTM obj ffd) * ffd.lattice_transform.value
modBBMin = getModContextBBoxMin obj ffd
modBBMax = getModContextBBoxMax obj ffd
point1PosWorld = modBBMin + (ffdPoint * (modBBMax - modBBMin)) * (inverse modTM) * objTM
return point1PosWorld
)

fn GetFFDCoords obj ffd worldPoint =
(
objTM = obj.objectTransform
modTM = (getModContextTM obj ffd) * ffd.lattice_transform.value
modBBMin = getModContextBBoxMin obj ffd
modBBMax = getModContextBBoxMax obj ffd
controlPointPos = (worldPoint - modBBMin) * (inverse objTM) / (modBBMax - modBBMin)
print ("Final: " + controlPointPos as string)
)
0 Likes
335 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Persistence pays off I guess.

(
-- This script converts from FFD space to world space and back again.
-- Neil Marshall neil@eightlines.com 12/31/2011
-- If you use this code please credit me.

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

print ("Before FFD Space: " + obj.modifiers.control_point_3 as string)
thePoint = FFDSpaceToWorldSpace obj obj.modifiers obj.modifiers.control_point_3

if thePoint != undefined then
(
print ("WorldSpace: " + thePoint as string)
point name:"tester" pos:thePoint
obj.modifiers.control_point_3 = WorldSpaceToFFDSpace obj obj.modifiers thePoint
print ("After FFD Space: " + obj.modifiers.control_point_3 as string)
)

""
)
0 Likes