Media and Entertainment Technologies Laboratory


XNA Utilities MAXScript for 3DS Max

An annoying problem when using 3D Studio Max models in XNA is that the pivot points you set in 3DS Max don't end up being the pivot points in the XNA model. Now, you can do Reset XForm and that will set the origin of the pivot point correctly, but it resets the axis to the world X, Y, and Z, which is not what you want in many cases.

So, I created this script that fixes this problem. The script is Right click on the link and choose Save As.


To install you either:

In the Utilities Rollout, hit the MaxScript button and choose Run Script. Select the script to run. This installs the utility. Then choose it from the Utilities list box to display it.

Alternatively, you can drop the utility into the 3D Studio Max Scripts/Startup directory and it will be automatically loaded on Startup.

How it works

A 3D Studio Max node has a transform associated with it (just called transform). This sets where the origin of the node local coordinate system is relative to the parent. This is the pivot point. Also associated with the node is an object offset transform. The mesh vertices are multiplied by the object offset transform, then the node transform then the parent transform. This is what allows you to freely move the pivot point. If you move the pivot point, it changes the node transform. To keep it from moving the model when you move the pivot point, the object offset transform is changed by an inverse amount, cancelling the effect on the vertices.

The problem is that what XNA is getting is not the vertices after the object offset transform, which sets the objects relative to the pivot. Instead, it is getting the actual model vertices and only the modifier stack has been applied. So, the transform for the bone in XNA is the product of the object offset transform and the node transform. For pivot points to work right, the object offset transform needs to be an identity matrix. I created a script that zeros that transform and creates an XForm modifier on the stack that does the same transformation. Since XNA gets the vertices after modifiers, it all works.