Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / FFD Control Point to World Space and Back Again
  RSS 2.0 ATOM  

FFD Control Point to World Space and Back Again
Rate this thread
 
62385
 
Permlink of this thread  
avatar
  • Location: Toronto, Ontario, Canada
  • Total Posts: 40
  • Joined: 28 February 2007 11:24 AM

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 [0, 0, 0] -> [0, 0, 0.83333]

“Orig: [0,0,0]”
“Point 1: [5.04469,-3.58221,1.49507]”
“Final: [0,0,0.833333]”

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)
 )


Replies: 0
avatar
  • Location: Toronto, Ontario, Canada
  • Total Posts: 40
  • Joined: 28 February 2007 11:24 AM
  • Permlink of this post

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[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)
 )
 
 
""
)


Replies: 0