Tukee myös FFD 2x2x2 modifieria
-- FFD Points
--
-- www.verajankorva.com
__aCPPoints = #()
/*** Create point helpers for every ffd control point ***/
fn fnCreatePoints _obj =
(
obj = _obj
m = obj.modifiers[1]
if ((classof m) != FFD_4X4X4) and ((classof m) != FFD_2x2x2) do
(
messageBox "No FFD modifier found"
return 0
)
animateAll m
iCpCount = 0
if (classof m) == FFD_4X4X4 do
iCpCount = 64
if (classof m) == FFD_2x2x2 do
iCpCount = 8
__aCPPoints = #()
for i=1 to iCpCount do
(
p = point()
p.pos = fnGetCpPos obj m i
append __aCPPoints p
)
sScript = stringStream ""
format "dependsOn " to:sScript
for i=1 to __aCPPoints.count do
format "$% " __aCPPoints[i].name to:sScript
format "\n" to:sScript
format "b = $%\n" obj.name to:sScript
format "m = b.modifiers[1]\n" to:sScript
for i=1 to __aCPPoints.count do
format "cp% = m.control_point_%\n" i i to:sScript
format "objTM = b.objectTransform\n" to:sScript
format "modTM = (getModContextTM b m) * m.lattice_transform.value\n" to:sScript
format "modBBMin=getModContextBBoxMin b m\n" to:sScript
format "modBBMax=getModContextBBoxMax b m\n" to:sScript
for i=1 to __aCPPoints.count do
(
format "cp%World = ($%.pos * (inverse objTM) * modTM - modBBMin) / (modBBMax - modBBMin)\n" i __aCPPoints[i].name to:sScript
format "m[#master][#control_point_%].value = cp%World\n" i i to:sScript
)
format "(matrix3 [1,0,0] [0,1,0] [0,0,1] [-1.98109,1.23891,0])\n" to:sScript
p = point()
ts = Transform_Script()
p.transform.controller = ts
ts.script = sScript
)
/*** Get control point position in world space ***/
fn fnGetCpPos _obj _ffd _iCpIndex =
(
cp = _ffd[#master]["control_point_"+(_iCpIndex as string)].value
objTM = _obj.objectTransform
modTM = (getModContextTM _obj _ffd) * _ffd.lattice_transform.value
modBBMin = getModContextBBoxMin _obj _ffd
modBBMax = getModContextBBoxMax _obj _ffd
cpWorld = (modBBMin + (cp * (modBBMax - modBBMin)) * (inverse modTM) * objTM)
return cpWorld
)
fnCreatePoints $