Quick maxscript question, maybe somebody could help me here with it. If not I will ask elsewhere...
I have this function which takes local space within a transform and converts it to world space. I then have the opposite function. I pulled the majority of these functions from maxscript help forums online. Here is the code for the world->local function
fn WorldToLocalPos obj ffdmod pos = (
objTM = obj.objecttransform
modTM = (getModContextTM obj ffdmod) * ffdmod.lattice_transform.value
modBBMin = getModContextBBoxMin obj ffdmod
modBBMax = getModContextBBoxMax obj ffdmod
-- correct for 0-size bx
boxSize = (modBBMax-modBBMin)
if (boxSize.x == 0) then boxSize.x = 1.0/1000.0
if (boxSize.y == 0) then boxSize.y = 1.0/1000.0
if (boxSize.z == 0) then boxSize.z = 1.0/1000.0
(pos - modBBMin) * (inverse objTM) * modTM / boxSize
-- was: (pos - modBBMin) * (inverse objTM) * inverse modTM / boxSize
),
I personally added the size correcting bit for 0 volume bounding boxes, as the zero height bounding box was found to crash max. Something I also learned while playing with FFD boxes was that max handles them in the exact same way this code does, which is why a 0 height FFD box still has its top control points set to non-zero.
Anyway, my problem is this...
passing this [333.333,-166.667,1000] inside boxSize [1000,1000,1004.53] gives this [333.333,-166.667,1995.47]
I don't understand matrix math since high school. Could somebody check my function for missing brackets, or something else that is wrong? I know the mistake is in the last line, but I don't fully understand what the matrix math is doing, so I don't know where to put the missing brackets.
Edit:
Nevermind. I see the problem. While the visual bounding box of the FFD modifier appears to be placed at 0,0,0, the actual transform center is half its overall height. Stupid. Gmax still shows it as 0-based, but asking it details about itself shows the opposite. The formula just needs to take that into consideration. .....Maths
Edit again:
Nope, my mistake. The problem was this:
if local to global is found via (modBBMin + (pos * boxSize) * (inverse modTM) * objTM)
then global to local must be found via (pos - modBBMin) * (inverse objTM) * modTM / boxSize
The error then being that modTM was inversed in the function for some reason. Which is probably why the guy who originally asked for it couldn't use it.
I've corrected the function above in case anybody wants it.