Forum Groups
  All forums
    Help & Feedback
      Work in progress
      Finished Art
      Non-Max related

Maxunderground news unavailable

Transform Script Follow Face
show user profile  griffinanimator
So I learned that I can use the following code to align a helper to a face.

dependsOn $rivet_mesh
-- First get the face normal vector.
faceNormal = in coordsys $rivet_mesh (polyop.getFaceNormal $rivet_mesh 305)
-- This is the desired up vector in world space
worldUpVector = [0,0,1]
-- Now get the cross-product of the face normal and the up vector.
-- This will give you a vector that is perpendicular to the plane defined
-- by the normal and the up vector. Normalize it to get a normal vector
-- pointing to the right.
rightVector = normalize (cross worldUpVector faceNormal)
-- Now using the face normal and the new vector,
-- get a vector that is perpendicular to the plane defined by the two.
-- This is the "local up vector", the vector that is the projection of
-- the world up vector on the face you selected. This one is perpendicular
-- to both the face normal and the right vector, and you have 3 normals now
-- that define the X, Y and Z of your new orthogonal coordinate system
-- for the UVW gizmo!
-- Note that this new vector can be seen as the SHADOW of the World Up vector
-- on the face of the object in the above image.
-- It is now displayed in green in the image below:
upVector = normalize ( cross rightVector faceNormal )
-- Using the 3 vectors, define a matrix3 value which represents the
-- coordinate system of the gizmo. The face normal is the Z axis,
-- the right vector is the X axis, and the local up vector is the Y axis:
Pos =matrix3 rightVector upVector faceNormal [0,0,0]

Now how do I get this to constantly evaluate? My goal is to have a helper constantly remain positioned and aligned with a face while the face is animated.
read 220 times
12/20/2011 10:03:28 PM (last edit: 12/20/2011 10:15:21 PM)
show user profile  griffinanimator
Actually this seems to be working alright now. I may have some problems with the up vector I chose, but good otherwise. Now to see how slow this is to evaluate.
FYI, I am trying to do a face setup much like the work done by Jeremy Earnst for Gears 3. He did his work in Maya, but I figure Max has everything I need.
read 214 times
12/20/2011 10:19:57 PM (last edit: 12/20/2011 10:19:57 PM)
show user profile  griffinanimator
I don't think I am accounting for face translation now. Earlier I was using this to attach to a vert and it worked great except I was not getting any rotation as would be expected.

dependsOn $rivet_mesh;
Pos = polyop.getvert $rivet_mesh 327

I used the above code in a Script Controller for the translation channel and that worked great. I guess I made the incorrect assumption that if I applied the "theMatrix" to the transform of my helper, it would define both rotation and translation.
read 208 times
12/20/2011 10:39:34 PM (last edit: 12/20/2011 10:39:34 PM)
#Maxforums IRC
Open chat window