I need to create a uvw planar gizmo for an object which needs to be oriented towards the camera regard less of the position or orientation of the object.
I tried using linking wire parameters to a camera oriented dummy and expressions, including using a orientation constraint, which doesn’t allow my to edit controller properties, so I’m stuck here.
I’m pretty sure this is a no brainer, but I’m quite analphabetic when it comes to expressions or scripts, so any advice is highly appreciated.
*Create a Camera
*Create a Box with size 50,50,50.
*Add UVWMap modifier
*Open TrackView, locate modified object, find the Gizmo track.
*Assign a Transform Script controller to the main gizmo track.
*Create a variable ‘theNode’ in the controller
*Assign the Node “Box01” by clicking “Assign Node” and picking the top track of the Box
*Create a variable ‘theCamera’ and assign the Node Camera01 to it.
*In the Expression field, notice there is a matrix3 value. Note the 4th element which is the position. By default, it would be [0,0,25] because the center of the box is 25 units in Z.
*Enter this:
oldPos = [0,0,25] --this is the original position of the gizmo in local space
theZ = normalize (theCamera.pos - theNode.pos) --this is the Z vector to look along
theX = normalize (cross theZ [0,0,1]) --this is the X local axis of the gizmo
theY = normalize (cross theZ theX) --this is the Y local axis (up) of the gizmo
theTM = theNode.transform --this is the node transform of the box
theTM.row4 = [0,0,0] --reset the position
--build a matrix and compensate for the box transformations:
(matrix3 theX theY theZ oldPos)*inverse theTM
Press Evaluate. The gizmo should now look at the camera. If you move the box or the camera, it should update. Note that I use the world Z up as the up vector, and that the gizmo would describe a sphere if you move it around the camera as it takes the position of the box and the position of the camera.
If you want the gizmo to not look at the camera but to STAY PARALLEL to the screen, you could replace theZ line with
theZ = theCamera.dir
This will keep the gizmo’s Z axis parallel to the camera’s Z axis and thus make the gizmo parallel to the XY projection plane of the camera. Notice that PFlow Shape Facing operator has this same option.
This works in Max 8 and Max 9. In earlier versions, the script would look slightly different.
Note: If you are using a Sphere or another object where the center is in the middle of the mesh, the old position in local space would be [0,0,0]. In the case of the box, I am using the box’s center instead of the gizmo’s center to shoot the look at ray, so it would be slighly skewed. If you are using the Screen Parallel mode though, it doesn’t matter.
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.